Exemple #1
0
    // Use this for initialization
    void Start()
    {
        stateMachine = new StateMachine <Mage>(this);
        stateMachine.ChangeState(AttackState.getInstance());

        allEnemies = GameObject.FindGameObjectsWithTag("Enemy");
        enemy      = FindClosestEnemy();

        nav = GetComponent <UnityEngine.AI.NavMeshAgent> ();
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         if (fireballReady)
         {
             Debug.Log("casting fireball");
             CastFireball();
         }
         else
         {
             Debug.Log("fireball is on cooldown");
         }
     }
     if (mage.stateMachine.currentState == AttackState.getInstance())
     {
         if (magicBoltReady)
         {
             AutoAttack(mage.enemy);
         }
     }
 }
Exemple #3
0
 // Update is called once per frame
 void Update()
 {
     //transform.LookAt(enemy);
     enemy = FindClosestEnemy();
     if (
         Vector3.Distance(transform.position, enemy.transform.position) >= attackDistance
         )
     {
         Debug.Log("GO TOWARD ENEMY");
         //Approach(enemy);
         if (stateMachine.currentState != AttackState.getInstance())
         {
             stateMachine.ChangeState(ChaseState.getInstance());
         }
     }
     if (
         Vector3.Distance(transform.position, enemy.transform.position) <= attackDistance &&
         Vector3.Distance(transform.position, enemy.transform.position) > runDistance
         )
     {
         Debug.Log("ATTACK ENEMY");
         if (stateMachine.currentState != AttackState.getInstance())
         {
             stateMachine.ChangeState(AttackState.getInstance());
         }
     }
     if (Vector3.Distance(transform.position, enemy.transform.position) <= runDistance)
     {
         Debug.Log("FLEE FROM ENEMY");
         //Flee(enemy);
         if (stateMachine.currentState != FleeState.getInstance())
         {
             stateMachine.ChangeState(FleeState.getInstance());
         }
     }
 }