Esempio n. 1
0
 public abstract void Entry(State prevState=null);
Esempio n. 2
0
 public abstract void Exit(State nextState=null);
Esempio n. 3
0
        //FSM Enemy AI
        public void doAI()
        {
            switch (state)
            {
                case State.IDLE:
                {
                    Vector3 finalPosition;
                    if(Random.Range(0f, 1.0f) > (AttackPlayerChance/100))
                    {
                        finalPosition = GetRandomPosition();
                        state = State.WALK;
                    }
                    else
                    {
                        finalPosition = new Vector3(Player.transform.position.x, 0, Player.transform.position.z);
                        state = State.ATTACK;
                    }

                    agent.SetDestination(finalPosition);

            #if UNITY_EDITOR
                    UnityEngine.Debug.DrawLine(transform.position, finalPosition, Color.white, 0.01f);
            #endif
                }

                break;

                case State.ATTACK:
                {
                    Vector3 playerDirection = Player.transform.position - transform.position;
                    playerDirection.Normalize();

                    Vector3 finalPosition = Player.transform.position + playerDirection;

                    agent.SetDestination(finalPosition);

            #if UNITY_EDITOR
                    UnityEngine.Debug.DrawLine(transform.position, finalPosition, Color.red, 0.01f);
            #endif
                }
                break;

                case State.WALK:
                {
                    if (agent.velocity.sqrMagnitude <= 1)
                    {
                        Vector3 finalPosition = GetRandomPosition();
                        agent.SetDestination(finalPosition);
            #if UNITY_EDITOR
                        UnityEngine.Debug.DrawLine(transform.position, finalPosition, Color.green, 0.01f);
            #endif
                    }
                }
                break;

                case State.DEFEND:
                {
                    state = State.IDLE;
                }
                break;
            }
        }
Esempio n. 4
0
 void Start()
 {
     agent = GetComponent<NavMeshAgent> ();
     state = State.IDLE;
 }
Esempio n. 5
0
        void OnCollisionEnter(Collision collision)
        {
            Characters.PlayerCtrl player = collision.gameObject.GetComponent<Characters.PlayerCtrl>();
            if(player != null)
            {
                player.ProcessCollision(this.gameObject);

                Vector3 finalPosition = GetRandomPosition();
                agent.SetDestination(finalPosition);
            #if UNITY_EDITOR
                UnityEngine.Debug.DrawLine(transform.position, finalPosition, Color.green, 0.01f);
            #endif
                state = State.WALK;
            }
        }
Esempio n. 6
0
		public override void Exit(State nextState = null)
		{
			m_script.ticker = m_script.tickerFrequency;
		}
Esempio n. 7
0
		public override void Entry(State prevState = null)
		{
			Debug.Log("Start Walk");
		}