Advertisement
Guest User

Unity Gems FSM Test

a guest
Nov 28th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TestStates : StateMachineBehaviourEx {
  5.    
  6.     public enum MyStates {
  7.        
  8.         A,
  9.         B,
  10.     }
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.    
  15.         useGUI = true;
  16.         currentState = MyStates.A;
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.    
  22.     }
  23.    
  24.     void OnGUI() {
  25.        
  26.         GUILayout.Space(20f);
  27.         GUILayout.BeginHorizontal();
  28.        
  29.         if (GUILayout.Button("action 1", GUILayout.Height(20f))) {
  30.             currentState = MyStates.A;
  31.         }
  32.         if (GUILayout.Button("action 2", GUILayout.Height(20f))) {
  33.             currentState = MyStates.B;
  34.         }
  35.        
  36.         GUILayout.EndHorizontal();     
  37.     }
  38.    
  39.     IEnumerator A_EnterState() {
  40.        
  41.         Debug.Log("entered A");
  42.         yield return null;
  43.     }
  44.    
  45.     IEnumerator A_ExitState() {
  46.        
  47.         Debug.Log("exited A");
  48.         yield return null;
  49.     }
  50.    
  51.     IEnumerator B_EnterState() {
  52.        
  53.         Debug.Log("entered B");
  54.         yield return null;
  55.     }
  56.    
  57.     IEnumerator B_ExitState() {
  58.        
  59.         Debug.Log("exited B");
  60.         yield return null;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement