Advertisement
Guest User

Untitled

a guest
Aug 25th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TTTManager : MonoBehaviour
  5. {
  6.     public enum Turn
  7.     {
  8.         Player,
  9.         Computer
  10.     };
  11.     public static Turn TTTTurn;
  12.  
  13.     // Who will start first
  14.     void setRandomStarter()
  15.     {
  16.         int x = Random.Range(1, 2);
  17.  
  18.         if (x == 1)
  19.             TTTTurn = Turn.Player;
  20.         else
  21.             TTTTurn = Turn.Computer;
  22.    
  23.     }
  24.  
  25.     void Start()
  26.     {
  27.         setRandomStarter();
  28.     }
  29.  
  30.     void Update()
  31.     {
  32.  
  33.         if (TTTTurn == Turn.Player)
  34.         {
  35.             StartCoroutine(PlayerAction());
  36.             // You can start and 2nd++ coroutine that have to do with Player
  37.         }
  38.         else
  39.         {
  40.             StartCoroutine(ComputerAction());
  41.             // You can start and 2nd++ coroutine that have to do with Computer
  42.         }
  43.        
  44.     }
  45.  
  46.     void OnGUI()
  47.     {
  48.         if (TTTTurn == Turn.Player)
  49.             GUI.Label(new Rect(Screen.width - 200, 20, 150, 50), "Its Player Turn");
  50.         else
  51.             GUI.Label(new Rect(Screen.width - 200, 20, 150, 50), "Its Computer Turn");
  52.     }
  53.  
  54.     IEnumerator PlayerAction()
  55.     {
  56.         while (TTTTurn == Turn.Player)
  57.         {
  58.             // PLAYER ACTIONS HERE
  59.  
  60.             yield return null;
  61.  
  62.             // Test Code - Change turn
  63.             if (Input.GetKeyDown(KeyCode.Space))
  64.                 TTTTurn = Turn.Computer;
  65.         }
  66.        
  67.     }
  68.  
  69.     IEnumerator ComputerAction()
  70.     {
  71.         while (TTTTurn == Turn.Computer)
  72.         {
  73.             // COMPUTER ACTIONS HERE
  74.            
  75.             yield return null;
  76.  
  77.             // Test Code - Change turn
  78.             if (Input.GetKeyDown(KeyCode.Space))
  79.                 TTTTurn = Turn.Player;
  80.         }
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement