Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TTTManager : MonoBehaviour
- {
- public enum Turn
- {
- Player,
- Computer
- };
- public static Turn TTTTurn;
- // Who will start first
- void setRandomStarter()
- {
- int x = Random.Range(1, 2);
- if (x == 1)
- TTTTurn = Turn.Player;
- else
- TTTTurn = Turn.Computer;
- }
- void Start()
- {
- setRandomStarter();
- }
- void Update()
- {
- if (TTTTurn == Turn.Player)
- {
- StartCoroutine(PlayerAction());
- // You can start and 2nd++ coroutine that have to do with Player
- }
- else
- {
- StartCoroutine(ComputerAction());
- // You can start and 2nd++ coroutine that have to do with Computer
- }
- }
- void OnGUI()
- {
- if (TTTTurn == Turn.Player)
- GUI.Label(new Rect(Screen.width - 200, 20, 150, 50), "Its Player Turn");
- else
- GUI.Label(new Rect(Screen.width - 200, 20, 150, 50), "Its Computer Turn");
- }
- IEnumerator PlayerAction()
- {
- while (TTTTurn == Turn.Player)
- {
- // PLAYER ACTIONS HERE
- yield return null;
- // Test Code - Change turn
- if (Input.GetKeyDown(KeyCode.Space))
- TTTTurn = Turn.Computer;
- }
- }
- IEnumerator ComputerAction()
- {
- while (TTTTurn == Turn.Computer)
- {
- // COMPUTER ACTIONS HERE
- yield return null;
- // Test Code - Change turn
- if (Input.GetKeyDown(KeyCode.Space))
- TTTTurn = Turn.Player;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement