Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public enum TestStates
- {
- VoidState,
- EnumState
- }
- public class TestBehaviour : StateMachineBehaviourEx
- {
- public bool startWithVoidState = true;
- void Start()
- {
- // This state loop will fail when VoidState_EnterState sets the currentState to EnumState;
- // EnumState_EnterState() will never be run, nor the corresponding Update or ExitState routines.
- if (startWithVoidState)
- {
- Debug.Log("initializing to VoidState");
- currentState = TestStates.VoidState;
- }
- // This state loop will succeed until VoidState tries to execute EnumState, as before.
- else
- {
- Debug.Log("initializing to EnumState");
- currentState = TestStates.EnumState;
- }
- }
- void Update()
- {
- Debug.Log(currentState);
- }
- void VoidState_EnterState()
- {
- Debug.Log("entered VoidState");
- Debug.Log("moving into EnumState");
- currentState = TestStates.EnumState;
- }
- void VoidState_Update()
- {
- Debug.Log("updating VoidState");
- }
- void VoidState_ExitState()
- {
- Debug.Log("exiting VoidState");
- }
- IEnumerator EnumState_EnterState()
- {
- Debug.Log("entered EnumState");
- Debug.Log("waiting for a second");
- yield return new WaitForSeconds(1f);
- Debug.Log("moving into VoidState");
- currentState = TestStates.VoidState;
- }
- void EnumState_Update()
- {
- Debug.Log("updating EnumState");
- }
- void EnumState_ExitState()
- {
- Debug.Log("exiting EnumState");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement