From 4e0c7121c052bc2bd15be84ea51abfabe20f4a1f Mon Sep 17 00:00:00 2001 From: LeeJaeHyun Date: Thu, 12 Sep 2024 16:28:18 +0900 Subject: [PATCH] . --- Assets/02_Scripts/MonsterController.cs | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) 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); + } } + + }