This commit is contained in:
LeeJaeHyun 2024-09-12 16:28:18 +09:00
parent efdeae9c58
commit 4e0c7121c0

View File

@ -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<Transform>();
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);
}
}
}
}