Exemplo n.º 1
0
    /// <summary>
    /// 初始化状态机
    /// </summary>
    public void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState patrolState = new PatrolState(this.gameObject.transform.position, this.gameObject);

        patrolState.AddTransition(Transition.SawPlayer, StateID.Chase);
        patrolState.SetNavAgent(navAgent);

        ChaseState chaseState = new ChaseState(this.gameObject);

        chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol);
        chaseState.SetNavAgent(navAgent);
        this.transform.GetComponent <SphereCollider>().enabled = true;



        fsm.AddState(patrolState);
        fsm.AddState(chaseState);

        fsm.Start(StateID.Patrol);
    }