Exemplo n.º 1
0
	void SetBehavior ()
	{
        if (!_playerHealth.IsDead())
        {
            if (enmHealth._health > 0)
            {

                if (!Hited)
                {

                    if (PlayerVisible)
                    {

                        if (!navAgent.isStopped)
                        {

                            navAgent.SetDestination(positionTarget.transform.position);

                            if (navAgent.remainingDistance <= minDistance)
                            {
                                maxSpeed = 1f;
                            }

                            if (navAgent.remainingDistance > minDistance + 0.5f)
                            {

                                maxSpeed = 4f;
                            }

                            if (curSpeed > 0f && curSpeed <= (speedRun))
                            {

                                enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Walk;

                            }
                            else if (curSpeed > (speedRun))
                            {
                                enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Run;
                            }
                            else if (curSpeed == 0)
                            {

                                enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Idle;
                            }
                            curSpeed = navAgent.velocity.magnitude;
                        }
                        else
                        {
                            enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Idle;
                        }
                    }
                    else
                    {
                        enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Idle;
                    }


                    if (attackDetection.attack && attackCount <= 3)
                    {

                        attackCount++;
                        int nAttack = Random.Range(0, (attackList.Length));
                        if (nAttack == attackList.Length)
                        {
                            nAttack = attackList.Length - 1;
                        }
                        enemyBehContrl.CurrentBehavior = attackList[nAttack];


                    }
                    else if (attackCount > 3)
                    {
                        attackCount = 0;
                        enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Shout;

                    }
                }
                else
                {

                    enemyBehContrl.CurrentBehavior = EnemyBehaviorList.GetHit;
                    Hited = false;
                }
            }
            if (enmHealth._health <= 0 && !_isDead)
            {
                _isDead = true;
                navAgent.enabled = false;
                enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Dead;
                enmHealth.DeactivateCollider();
            }
        }
        else
        {
            navAgent.enabled = false;
            enemyBehContrl.CurrentBehavior = EnemyBehaviorList.Idle;
        }
	}