public void Start() { currentState = Thrall_States.Idle; target = PlayerManager.instance.player.transform; agent = GetComponent <NavMeshAgent>(); }
public void Update() { if (currentState == Thrall_States.Idle) { stateIndicationText.text = "Idle"; stateIndicationText.color = Color.white; } else if (currentState == Thrall_States.Walk) { stateIndicationText.text = "Chase"; stateIndicationText.color = Color.yellow; } else if (currentState == Thrall_States.Charge) { stateIndicationText.text = "Charge"; stateIndicationText.color = Color.red; } else if (currentState == Thrall_States.Attack) { stateIndicationText.text = "Attack"; stateIndicationText.color = Color.red; } else if (currentState == Thrall_States.Die) { stateIndicationText.text = "Dead"; stateIndicationText.color = Color.grey; } else if (currentState == Thrall_States.Death) { stateIndicationText.text = "Dead"; stateIndicationText.color = Color.grey; } //Debug.Log(currentState.ToString()); float distance = Vector3.Distance(target.position, transform.position); if (distance >= lr && !enemy.isAttacking) { currentState = Thrall_States.Idle; } if (distance <= lr && !enemy.isAttacking) { agent.SetDestination(target.position); currentState = Thrall_States.Walk; if (distance <= agent.stoppingDistance && !enemy.isAttacking) { FaceTarget(); currentState = Thrall_States.Idle; } } else if (distance <= agent.stoppingDistance && enemy.isAttacking) { currentState = Thrall_States.Charge; } /////////////////////////////////////////////////////////// if (currentState == Thrall_States.Idle) { t_Anim.SetInteger("animState", 1); } /////////////////////////////////////////////////////////// if (currentState == Thrall_States.Walk) { t_Anim.SetInteger("animState", 2); } /////////////////////////////////////////////////////////// if (currentState == Thrall_States.Charge) { t_Anim.SetInteger("animState", 3); } /////////////////////////////////////////////////////////// if (currentState == Thrall_States.Attack) { t_Anim.SetInteger("animState", 4); } /////////////////////////////////////////////////////////// if (currentState == Thrall_States.Die) { t_Anim.SetInteger("animState", 5); } if (enemy.isDead) { currentState = Thrall_States.Die; lr = 0f; this.GetComponent <NavMeshAgent>().speed = 0f; } }