Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        startStateTime = Time.unscaledTime;
        stateMachine   = new StateMachine <MonsterAI>(this);
        ai             = GetComponent <IAstarAI>();
        fov            = GetComponent <FovDetection>();
        monsterBrain   = GetComponent <MonsterBrain>();



        GoToNextState();
    }
    }                                                       //Instance of the StateMachine class



    private void Start()
    {
        //When start is called, set the initial state to Patrol, start a timer, this will change states every stateSeconds seconds to demo
        stateMachine = new StateMachine <PatrolAI>(this);
        fov          = GetComponent <FovDetection>();
        stateMachine.ChangeState(EnemyPatrolState.Instance);
        currentState = "patrol";
        gameTimer    = Time.time;
        ai           = GetComponent <IAstarAI>();
        ai.maxSpeed  = patrolSpeed;
        // Update the destination right before searching for a path as well.
        // This is enough in theory, but this script will also update the destination every
        // frame as the destination is used for debugging and may be used for other things by other
        // scripts as well. So it makes sense that it is up to date every frame.
        if (ai != null)
        {
            ai.onSearchPath += Update;
        }
    }