Advertisement
Guest User

Untitled

a guest
May 13th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class GameControl : MonoBehaviour {
  5.  
  6.     private static GameObject whoWinsTextShadow, player1MoveText, player2MoveText;
  7.  
  8.     private static GameObject player1, player2;
  9.  
  10.     public static int diceSideThrown = 0;
  11.     public static int player1StartWaypoint = 0;
  12.     public static int player2StartWaypoint = 0;
  13.  
  14.     public static bool gameOver = false;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.  
  19.         whoWinsTextShadow = GameObject.Find("WhoWinsText");
  20.         player1MoveText = GameObject.Find("Player1MoveText");
  21.         player2MoveText = GameObject.Find("Player2MoveText");
  22.  
  23.         player1 = GameObject.Find("Player1");
  24.         player2 = GameObject.Find("Player2");
  25.  
  26.         player1.GetComponent<FollowThePath>().moveAllowed = false;
  27.         player2.GetComponent<FollowThePath>().moveAllowed = false;
  28.  
  29.         whoWinsTextShadow.gameObject.SetActive(false);
  30.         player1MoveText.gameObject.SetActive(true);
  31.         player2MoveText.gameObject.SetActive(false);
  32.     }
  33.  
  34.     // Update is called once per frame
  35.     void Update()
  36.     {
  37.         if (player1.GetComponent<FollowThePath>().waypointIndex >
  38.             player1StartWaypoint + diceSideThrown)
  39.         {
  40.             player1.GetComponent<FollowThePath>().moveAllowed = false;
  41.             player1MoveText.gameObject.SetActive(false);
  42.             player2MoveText.gameObject.SetActive(true);
  43.             player1StartWaypoint = player1.GetComponent<FollowThePath>().waypointIndex - 1;
  44.         }
  45.  
  46.         if (player2.GetComponent<FollowThePath>().waypointIndex >
  47.             player2StartWaypoint + diceSideThrown)
  48.         {
  49.             player2.GetComponent<FollowThePath>().moveAllowed = false;
  50.             player2MoveText.gameObject.SetActive(false);
  51.             player1MoveText.gameObject.SetActive(true);
  52.             player2StartWaypoint = player2.GetComponent<FollowThePath>().waypointIndex - 1;
  53.         }
  54.  
  55.         if (player1.GetComponent<FollowThePath>().waypointIndex ==
  56.             player1.GetComponent<FollowThePath>().waypoints.Length)
  57.         {
  58.             whoWinsTextShadow.gameObject.SetActive(true);
  59.             whoWinsTextShadow.GetComponent<Text>().text = "Player 1 Wins";
  60.             gameOver = true;
  61.         }
  62.  
  63.         if (player2.GetComponent<FollowThePath>().waypointIndex ==
  64.             player2.GetComponent<FollowThePath>().waypoints.Length)
  65.         {
  66.             whoWinsTextShadow.gameObject.SetActive(true);
  67.             player1MoveText.gameObject.SetActive(false);
  68.             player2MoveText.gameObject.SetActive(false);
  69.             whoWinsTextShadow.GetComponent<Text>().text = "Player 2 Wins";
  70.             gameOver = true;
  71.         }
  72.     }
  73.  
  74.     public static void MovePlayer(int playerToMove)
  75.     {
  76.         switch (playerToMove) {
  77.             case 1:
  78.                 player1.GetComponent<FollowThePath>().moveAllowed = true;
  79.                 break;
  80.  
  81.             case 2:
  82.                 player2.GetComponent<FollowThePath>().moveAllowed = true;
  83.                 break;
  84.         }
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement