diff --git a/Assets/02_Scripts/MonsterController.cs b/Assets/02_Scripts/MonsterController.cs index c56a802..026a12f 100644 --- a/Assets/02_Scripts/MonsterController.cs +++ b/Assets/02_Scripts/MonsterController.cs @@ -10,16 +10,43 @@ public class MonsterController : MonoBehaviour } public State monsterState; + public float attackDist = 2.0f; + public float traceDist = 10.0f; + + public bool isDie = false; + + public Transform playerTr, monsterTr; // Start is called before the first frame update void Start() { - + playerTr = GameObject.Find("Player").GetComponent(); + monsterTr = transform; } - // Update is called once per frame - void Update() + IEnumerator CheckMonsterState() { + while (!isDie) + { + // 거리 계산 + float distance = Vector3.Distance(playerTr.position, monsterTr.position); + if (distance <= attackDist) + { + monsterState = State.ATTACK; + } + else if (distance <= traceDist) + { + monsterState = State.TRACE; + } + else + { + monsterState = State.IDLE; + } + + yield return new WaitForSeconds(0.3f); + } } + + }