// Update is called once per frame
 void Update()
 {
     // the states only are using the AI when the 'active' is true, so the tank cant move until
     // GameManager say it
     if (active)
     {
         //all the states wants to know the distance,
         if (target)
         {
             this.actualDistance = Vector3.Distance(transform.position, target.transform.position);
             if (transform.position.x < target.transform.position.x) //direction of the target in X
             {
                 lookDirection = 1;
             }
             else
             {
                 lookDirection = -1;
             }
             transform.localScale = new Vector3(lookDirection, 1, 1);
         }
         else
         {
             this.actualDistance = 0;
         }
         if (actualState != null) //just check in case
         {
             actualState.UpdateState();
         }
         else
         {
             Debug.Log("Error in some state change, REDIRECTING TO PATROL STATE AT " + gameObject.name);
             actualState = patrolingState;
         }
     }
 }
 public float actualDistance; // the distance to the target
 void Awake()
 {
     followingState = new StateFollow(this);
     patrolingState = new StatePatrol(this);
     firingState    = new StateFire(this);
     actualState    = patrolingState;
 }
    public void SetState(IStateEnemy newState)
    {
        if (currentState != null)
        {
            currentState.Exit();
        }

        currentState = newState;
        currentState.Enter();
    }
예제 #4
0
    // We use this function in the ChaseRadius script
    // Depending if the player is in the range it changes the current state
    public void changeState(ICharacter characterToChase, states nextState)
    {
        switch (nextState)
        {
        case states.searching:
            state = new Searching(rb2d, speed);
            break;

        case states.chasing:
            state = new Chasing(rb2d, speed, characterToChase);
            break;

        case states.meeleCombat:
            state = new MeeleCombat(rb2d, speed);
            break;
        }
    }
예제 #5
0
 private void initReferences()
 {
     rb2d        = GetComponent <Rigidbody2D>();
     healthCom   = new HealthComponent(this);
     state       = new Searching(rb2d, speed);
     animator    = GetComponentInChildren <Animator>();
     animCom     = new AnimationController(animator);
     meeleAttack = GetComponentInChildren <MeeleAttack>();
     rangeAttack = GetComponentInChildren <RangeAttack>();
     if (meeleAttack != null)
     {
         attackComponents.Add(meeleAttack);
     }
     if (rangeAttack != null)
     {
         attackComponents.Add(rangeAttack);
     }
 }