// Start is called before the first frame update void Start() { Instance = this; plugModel.transform.position = new Vector3(Random.Range(-39, 70), Random.Range(-43, 17), Random.Range(-40, -8)); // Initialize the plug in random location at start plugModel.transform.Rotate(0, 0, Random.Range(0, 360)); //The timer used in the game uses a script that is part of Photon. From the project root directory, the path to the script is Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/CountdownTimer.cs Photon.Pun.UtilityScripts.CountdownTimer timer = timerText.GetComponent <Photon.Pun.UtilityScripts.CountdownTimer>(); UnityEngine.UI.Text timerUI = timerText.GetComponent <UnityEngine.UI.Text>(); float time = GetTime(); timer.Countdown = time; //Sets the timer object's countdown, which is the time it starts counting down from. timerUI.text = time.ToString(); //Sets the text in the UI element for the timer to the starting time. //Assigns the function for resetting the game to the reset button, and hides the reset button from view at the start of the game. restartButton.onClick.AddListener(OnRestartButtonClick); restartButton.gameObject.SetActive(false); if (inEditor) { PhotonNetwork.OfflineMode = true; //This is strictly for development and testing purposes. } else if (PhotonNetwork.IsMasterClient) { SetPlugPlayer(); } else { SetObserver(); } }
// Start is called before the first frame update void Start() { var rand = new System.Random(); // Randomly choose puzzle piece to be displaced moveablePiece = puzzlePieces[rand.Next(puzzlePieces.Length)].gameObject; moveablePiece.gameObject.GetComponent <MovePuzzlePiece>().pieceLocked = false; // unlock dynamic piece // move dynamic piece to starting position float z = moveablePiece.transform.position.z; moveablePiece.transform.position = new Vector3(-50f, 0f, z); Instance = this; //The timer used in the game uses a script that is part of Photon. From the project root directory, the path to the script is Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/CountdownTimer.cs Photon.Pun.UtilityScripts.CountdownTimer timer = timerText.GetComponent <Photon.Pun.UtilityScripts.CountdownTimer>(); UnityEngine.UI.Text timerUI = timerText.GetComponent <UnityEngine.UI.Text>(); float time = GetTime(); timer.Countdown = time; //Sets the timer object's countdown, which is the time it starts counting down from. timerUI.text = time.ToString(); //Sets the text in the UI element for the timer to the starting time. //Assigns the function for resetting the game to the reset button, and hides the reset button from view at the start of the game. restartButton.onClick.AddListener(OnRestartButtonClick); restartButton.gameObject.SetActive(false); if (inEditor) { PhotonNetwork.OfflineMode = true; //This is strictly for development and testing purposes. } else if (PhotonNetwork.IsMasterClient) { SetPlugPlayer(); } else { SetObserver(); } }
//This function is not run by the MasterClient, only other clients. (In other words, only the observer.) //It mirrors a lot of the functionality that exists in the Start function since only the MasterClient reloads the scene. public void ResetGame() { winText.enabled = false; loseText.enabled = false; didWin = false; //Resets didWin bool to false, because if it is not reset, the win text is displayed when the timer runs out after a reset. Photon.Pun.UtilityScripts.CountdownTimer timer = timerText.GetComponent <Photon.Pun.UtilityScripts.CountdownTimer>(); UnityEngine.UI.Text timerUI = timerText.GetComponent <UnityEngine.UI.Text>(); float time = GetTime(); timer.Countdown = time; timerUI.text = time.ToString(); restartButton.gameObject.SetActive(false); //The observer script and buttons need to be explicity re-enable by the observer because the Plug Player (who is the MasterClient) reloads the scene, and gets its scripts re-enabled that way. plugModel.GetComponent <ObserverController>().enabled = true; plugModel.GetComponent <ObserverController>().enableButtons(); timerText.GetComponent <Photon.Pun.UtilityScripts.CountdownTimer>().enabled = true; //Re-enables the timer. Photon.Pun.UtilityScripts.CountdownTimer.OnCountdownTimerHasExpired += OnCountdownTimerHasExpired; //Re-enables the function that executes when the timer runs out. Photon.Pun.UtilityScripts.CountdownTimer.SetStartTime(); //Starts the timer again. }
private void Awake() { instance = this; }