Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public enum TestStates
  5. {
  6.     VoidState,
  7.     EnumState
  8. }
  9.  
  10. public class TestBehaviour : StateMachineBehaviourEx
  11. {
  12.     public bool startWithVoidState = true;
  13.    
  14.     void Start()
  15.     {
  16.         // This state loop will fail when VoidState_EnterState sets the currentState to EnumState;
  17.         // EnumState_EnterState() will never be run, nor the corresponding Update or ExitState routines.
  18.         if (startWithVoidState)
  19.         {
  20.             Debug.Log("initializing to VoidState");
  21.             currentState = TestStates.VoidState;
  22.         }
  23.         // This state loop will succeed until VoidState tries to execute EnumState, as before.
  24.         else
  25.         {
  26.             Debug.Log("initializing to EnumState");
  27.             currentState = TestStates.EnumState;
  28.         }
  29.        
  30.     }
  31.    
  32.     void Update()
  33.     {
  34.         Debug.Log(currentState);
  35.     }
  36.  
  37.     void VoidState_EnterState()
  38.     {
  39.         Debug.Log("entered VoidState");
  40.        
  41.         Debug.Log("moving into EnumState");
  42.         currentState = TestStates.EnumState;
  43.     }
  44.    
  45.     void VoidState_Update()
  46.     {
  47.         Debug.Log("updating VoidState");
  48.     }
  49.    
  50.     void VoidState_ExitState()
  51.     {
  52.         Debug.Log("exiting VoidState");
  53.     }
  54.    
  55.     IEnumerator EnumState_EnterState()
  56.     {
  57.         Debug.Log("entered EnumState");
  58.        
  59.         Debug.Log("waiting for a second");
  60.         yield return new WaitForSeconds(1f);
  61.        
  62.         Debug.Log("moving into VoidState");
  63.         currentState = TestStates.VoidState;
  64.     }
  65.    
  66.     void EnumState_Update()
  67.     {
  68.         Debug.Log("updating EnumState");
  69.     }
  70.    
  71.     void EnumState_ExitState()
  72.     {
  73.         Debug.Log("exiting EnumState");
  74.     }  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement