コード例 #1
0
    // in spot
    // leave when the time out, switch to the looking for wp 1
    void In_Spot()
    {
        // if not ready and I am not in this spot, witch to the in spot state
        if (!spot.Is_Ready())
        {
            if (!spot.Is_In_This_Place(role))
            {
                state = STATE.Looking_WP_2;
                // stop
                agent.Stop();
                // play animation.
                return;
            }
        }

        // count down
        time_to_leave -= Time.deltaTime;
        if (time_to_leave <= 0.0f)
        {
            // if has a next place need to go
            if (spot.next_place)
            {
                place = spot.next_place;
                state = STATE.Walking_to_WP_1;
                // set the destination
                agent.SetDestination(place.transform.position);
                // play animation.
            }
            else
            {
                state = STATE.Looking_WP_1;
                // play animation.
            }
        }
    }
コード例 #2
0
    // looking for a wp 1, and than switch to walking wp 1state
    void Looking_For_WP_1()
    {
        // find all the wp1
        HHK_Way_Point_Level_1[] wp1s = FindObjectsOfType <HHK_Way_Point_Level_1>();
        place = wp1s[Random.Range(0, wp1s.Length)];

        // switch to walking
        state = STATE.Walking_to_WP_1;
        // set the destination
        agent.SetDestination(place.transform.position);
        // play animation.
    }
コード例 #3
0
    // looking for a wp 1, and than switch to walking wp 1state
    void Looking_For_WP_1()
    {
        // find all the wp1
        HHK_Way_Point_Level_1[] wp1s = FindObjectsOfType <HHK_Way_Point_Level_1>();
        place = wp1s[Random.Range(0, wp1s.Length)];

        // switch to walking
        state = STATE.Walking_to_WP_1;
        // set the destination
        agent.SetDestination(place.transform.position);
        // play animation.
        role_controller.Play(HHK_Role_Controller.AnimName.motion);
        agent.speed = speed_run;
    }
コード例 #4
0
    // in spot
    // leave when the time out, switch to the looking for wp 1
    void In_Spot()
    {
        role_controller.Play(HHK_Role_Controller.AnimName.idle);
        // if not ready and I am not in this spot, witch to the in spot state
        if (!spot.Is_Ready())
        {
            if (!spot.Is_In_This_Place(role))
            {
                state = STATE.Looking_WP_2;
                // stop
                agent.Stop();
                // play animation.
                return;
            }
        }

        // rotataion
        transform.rotation = Quaternion.Lerp(transform.rotation, spot.transform.rotation,
                                             agent.angularSpeed * Time.deltaTime);

        // count down
        time_to_leave -= Time.deltaTime;
        if (time_to_leave <= 0.0f)
        {
            // if has a next place need to go
            if (spot.next_place)
            {
                place = spot.next_place;
                state = STATE.Walking_to_WP_1;
                // set the destination
                agent.SetDestination(place.transform.position);
                // play animation.
                role_controller.Play(HHK_Role_Controller.AnimName.motion);
                agent.speed = speed_run;
            }
            else
            {
                state = STATE.Looking_WP_1;
                // play animation.
            }
        }
    }
コード例 #5
0
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables>();

        // find all the wp1
        HHK_Way_Point_Level_1[] wp1s = HHK_Way_Point_Level_1.FindAllPlace();
        if (npc.place == null || wp1s.Length <= 1)
        {
            npc.place = wp1s[Random.Range(0, wp1s.Length)];
        }
        else
        {
            // no same place again
            HHK_Way_Point_Level_1 wp = wp1s[Random.Range(0, wp1s.Length)];
            while (wp == npc.place)
            {
                wp = wp1s[Random.Range(0, wp1s.Length)];
            }
            npc.place = wp;
        }
        // send event
        Fsm.Event(walkingToPlace);
    }