Example #1
0
    //Abstract classes are never used by the parent, only the child

    //Chase the player
    void ChaseAndFire(AISense sense)
    {
        isSpotted = true;

        //This is used to get a direction from the player and our current position
        Vector2 dir = GameManager.instance.player.transform.position - transform.position;

        //Get the angle of the direction
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        //Angel axis
        Quaternion qto = Quaternion.AngleAxis(angle, Vector3.forward);

        //Euler
        Quaternion qto2 = Quaternion.Euler(qto.eulerAngles.x,
                                           qto.eulerAngles.y,
                                           qto.eulerAngles.z);

        //Set the rotation
        transform.rotation = qto2;

        //Move up, What ever direction the enemy is facing he will move towards it
        transform.position += transform.right * 2 * Time.deltaTime;

        //If we cannot see the player
        if (!sense.CanSee(GameManager.instance.player))
        {
            //Set the current state to patrol
            currentState = AIStates.Patrol;
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        //Set the curren state to patrolling
        currentState = AIStates.Patrol;

        //sense is the component of our enemy
        sense = GetComponent <AISense>();
    }
Example #3
0
    //Patrol method for rotating
    void Patrol(Text text, AISense sense)
    {
        isSpotted = false;
        // Do Patrol
        transform.Rotate(0, 0, -Time.deltaTime * rotationSpeed);

        // Check for Transitions
        if (sense.CanSee(GameManager.instance.player) || sense.CanHear(GameManager.instance.player, GameManager.instance.noiseMaker.volume))
        {
            //Since spotted, increase the counter
            text.text = "Times Spotted: " + ++timesSpotted;

            //currentstate is now Chasing
            currentState = AIStates.ChaseAndFire;
        }
    }
Example #4
0
    //Enemy State Machine Virtual method
    public virtual void StateMachine(GameObject spotted, Text text, AISense sense)
    {
        // AI States are based on enum value
        switch (currentState)
        {
        //If the currentstate is Patroling
        case AIStates.Patrol:
            // Do patrol work
            spotted.SetActive(false);
            Patrol(text, sense);
            break;

        //If the current state is chasing
        case AIStates.ChaseAndFire:
            // Do patrol work
            spotted.SetActive(true);
            ChaseAndFire(sense);
            break;
        }
    }
Example #5
0
 public void ChangeState(AISense newMode)
 {
     // Change our state
     aiSense = newMode;
 }