Ejemplo n.º 1
0
    public static void MoveTowardPlayer(MoleEnemyController enemy, GameObject player, float speed)
    {
        float dir = player.transform.position.x - enemy.transform.position.x;

        dir = (dir > 0)? 1 : -1; //Transform in just a sign
        enemy.gameObject.GetComponent <Rigidbody2D>().AddForce(new Vector2(dir * speed, 0));
    }
Ejemplo n.º 2
0
 /**
  * Call a friend for help
  * Check on all GameObject with the specific tag for friends
  *
  * return true if one friend found, otherwise, return false
  */
 public bool CallForHelp()
 {
     // This function will ask one friend currently fighting to block player (Change state to block)
     GameObject[] friends = GameObject.FindGameObjectsWithTag("enemy");
     foreach (GameObject o in friends)
     {
         MoleEnemyController friend = o.GetComponent <MoleEnemyController>();
         if (friend.isFighting == true)
         {
             friend.SetState(MoleStateFactory.creaBlockAttack());
             return(true);
         }
     }
     return(false);
 }