몬스터 플레이어 감지 범위 구현 테스트
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -11,9 +11,13 @@ namespace TON
|
|||||||
public class MonsterBase : MonoBehaviour, IDamage
|
public class MonsterBase : MonoBehaviour, IDamage
|
||||||
{
|
{
|
||||||
public int id; // 적 고유 ID
|
public int id; // 적 고유 ID
|
||||||
public int hp; // HP
|
public float currentHP = 100; // HP
|
||||||
public int damage; // 공격력
|
|
||||||
|
public string name; // 몬스터 명 or 프리팹 명
|
||||||
|
public string monsterType; // 몬스터 타입 ex : melee, ranged
|
||||||
|
|
||||||
|
|
||||||
|
// public int damage; // 공격력
|
||||||
public float speed = 2; // 이동속도
|
public float speed = 2; // 이동속도
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -22,6 +26,8 @@ namespace TON
|
|||||||
|
|
||||||
private Vector3 _direction;
|
private Vector3 _direction;
|
||||||
private bool _isWalking;
|
private bool _isWalking;
|
||||||
|
private bool _isHit;
|
||||||
|
private bool _isDetect;
|
||||||
private float _currentTime;
|
private float _currentTime;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -32,6 +38,9 @@ namespace TON
|
|||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject _target;
|
private GameObject _target;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private Collider2D _collider;
|
||||||
|
|
||||||
public float defencePower;
|
public float defencePower;
|
||||||
|
|
||||||
@@ -45,7 +54,8 @@ namespace TON
|
|||||||
_direction = new Vector3(1, 0, 0);
|
_direction = new Vector3(1, 0, 0);
|
||||||
|
|
||||||
_spriteRenderer.flipX = !(_direction.x > 0);
|
_spriteRenderer.flipX = !(_direction.x > 0);
|
||||||
|
_collider = GetComponent<Collider2D>();
|
||||||
|
|
||||||
// TODO: 몬스터 방어력 세팅 임시값
|
// TODO: 몬스터 방어력 세팅 임시값
|
||||||
defencePower = 10f;
|
defencePower = 10f;
|
||||||
}
|
}
|
||||||
@@ -56,7 +66,8 @@ namespace TON
|
|||||||
// todo : 타겟 감지 >> 몬스터의 원형 시야 안에 플레이어가 충돌했는지 여부
|
// todo : 타겟 감지 >> 몬스터의 원형 시야 안에 플레이어가 충돌했는지 여부
|
||||||
// todo : 충돌 했으면 attack 전환 (바로 그냥 공격하게 따라가지 말고)
|
// todo : 충돌 했으면 attack 전환 (바로 그냥 공격하게 따라가지 말고)
|
||||||
// todo : 시야를 벗어났으면 idle 전환
|
// todo : 시야를 벗어났으면 idle 전환
|
||||||
|
|
||||||
|
_isDetect = false;
|
||||||
|
|
||||||
if (_isWalking)
|
if (_isWalking)
|
||||||
{
|
{
|
||||||
@@ -86,6 +97,11 @@ namespace TON
|
|||||||
_isWalking = true;
|
_isWalking = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isHit)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
_animator.SetBool("Walk", _isWalking); // 걷기 애니메이션
|
_animator.SetBool("Walk", _isWalking); // 걷기 애니메이션
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +119,26 @@ namespace TON
|
|||||||
|
|
||||||
public void ApplyDamage(float damage)
|
public void ApplyDamage(float damage)
|
||||||
{
|
{
|
||||||
// TODO: 몬스터 피해 값 코드
|
// 몬스터 피해 값 코드
|
||||||
// 체력이 감소되는 부분
|
// 체력이 감소되는 부분
|
||||||
// 몬스터 죽고 파괴되는 부분
|
// 몬스터 죽고 파괴되는 부분
|
||||||
// 피격됐을때 애니메이션
|
// 피격됐을때 애니메이션
|
||||||
|
|
||||||
|
float prevHP = currentHP;
|
||||||
|
currentHP -= damage;
|
||||||
|
|
||||||
|
if (prevHP > 0 && currentHP <= 0)
|
||||||
|
{
|
||||||
|
_animator.SetBool("Die", true); // 몬스터 죽는 애니메이션 트리거
|
||||||
|
Destroy(gameObject); // 몬스터 파괴
|
||||||
|
}
|
||||||
|
else if (prevHP > 0 && currentHP > 0)
|
||||||
|
{
|
||||||
|
_animator.SetBool("Hit", true); // 피격 애니메이션
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonsterAttack()
|
void MonsterAttack(GameObject player)
|
||||||
{
|
{
|
||||||
// 임시 반영 수정 예정
|
// 임시 반영 수정 예정
|
||||||
DamageCalculator damageCalculator = new DamageCalculator();
|
DamageCalculator damageCalculator = new DamageCalculator();
|
||||||
@@ -123,5 +152,16 @@ namespace TON
|
|||||||
|
|
||||||
Debug.Log($" 몬스터 공격! 최종 데미지: {damage}");
|
Debug.Log($" 몬스터 공격! 최종 데미지: {damage}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCollisionEnter2D(Collision2D other)
|
||||||
|
{
|
||||||
|
if (other.collider.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
_isDetect = true;
|
||||||
|
_animator.SetBool("Attack", _isDetect); // 공격 애니메이션 재생
|
||||||
|
MonsterAttack(other.gameObject); // 플레이어에게 공격
|
||||||
|
Debug.Log("감지됨");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"com.unity.cinemachine": "2.10.3",
|
"com.unity.cinemachine": "2.10.3",
|
||||||
"com.unity.collab-proxy": "2.6.0",
|
"com.unity.collab-proxy": "2.6.0",
|
||||||
"com.unity.feature.development": "1.0.1",
|
"com.unity.feature.development": "1.0.1",
|
||||||
|
"com.unity.ide.rider": "3.0.34",
|
||||||
"com.unity.textmeshpro": "3.0.6",
|
"com.unity.textmeshpro": "3.0.6",
|
||||||
"com.unity.timeline": "1.7.6",
|
"com.unity.timeline": "1.7.6",
|
||||||
"com.unity.ugui": "1.0.0",
|
"com.unity.ugui": "1.0.0",
|
||||||
|
|||||||
@@ -135,7 +135,7 @@
|
|||||||
},
|
},
|
||||||
"com.unity.ext.nunit": {
|
"com.unity.ext.nunit": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"depth": 2,
|
"depth": 1,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
@@ -155,8 +155,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"com.unity.ide.rider": {
|
"com.unity.ide.rider": {
|
||||||
"version": "3.0.28",
|
"version": "3.0.34",
|
||||||
"depth": 1,
|
"depth": 0,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.ext.nunit": "1.0.6"
|
"com.unity.ext.nunit": "1.0.6"
|
||||||
|
|||||||
Reference in New Issue
Block a user