Pause
How do I use Pause
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
495 protected internal void LocalCleanupAnythingInstantiated(bool destroyInstantiatedGameObjects)
496 {
497 if (tempInstantiationData.Count > 0)
498 {
499 Debug.LogWarning("It seems some instantiation is not completed, as instantiation data is used. You should make sure instantiations are paused when calling this method. Cleaning now, despite this.");
500 }
501
502 // Destroy GO's (if we should)
503 if (destroyInstantiatedGameObjects)
504 {
505 // Fill list with Instantiated objects
506 HashSet
507 foreach (PhotonView view in this.photonViewList.Values)
508 {
509 if (view.isRuntimeInstantiated)
510 {
511 instantiatedGos.Add(view.gameObject); // HashSet keeps each object only once
512 }
513 }
514
515 foreach (GameObject go in instantiatedGos)
516 {
517 this.RemoveInstantiatedGO(go, true);
518 }
519 }
520
521 // photonViewList is cleared of anything instantiated (so scene items are left inside)
522 // any other lists can be
523 this.tempInstantiationData.Clear(); // should be empty but to be safe we clear (no new list needed)
524 PhotonNetwork.lastUsedViewSubId = 0;
525 PhotonNetwork.lastUsedViewSubIdStatic = 0;
526 }
File name: NetworkingPeer.cs
Copy
3113 public void NewSceneLoaded()
3114 {
3115 if (this.loadingLevelAndPausedNetwork)
3116 {
3117 this.loadingLevelAndPausedNetwork = false;
3118 PhotonNetwork.isMessageQueueRunning = true;
3119 }
3120 // Debug.Log("OnLevelWasLoaded photonViewList.Count: " + photonViewList.Count); // Exit Games internal log
3121
3122 List
3123 foreach (KeyValuePair
3124 {
3125 PhotonView view = kvp.Value;
3126 if (view == null)
3127 {
3128 removeKeys.Add(kvp.Key);
3129 }
3130 }
3131
3132 for (int index = 0; index < removeKeys.Count; index++)
3133 {
3134 int key = removeKeys[index];
3135 this.photonViewList.Remove(key);
3136 }
3137
3138 if (removeKeys.Count > 0)
3139 {
3140 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
3141 Debug.Log("New level loaded. Removed " + removeKeys.Count + " scene view IDs from last level.");
3142 }
3143 }
File name: PhotonNetwork.cs
Copy
2652 public static void LoadLevel(int levelNumber)
2653 {
2654 networkingPeer.SetLevelInPropsIfSynced(levelNumber);
2655
2656 PhotonNetwork.isMessageQueueRunning = false;
2657 networkingPeer.loadingLevelAndPausedNetwork = true;
2658 Application.LoadLevel(levelNumber);
2659 }
File name: PhotonNetwork.cs
Copy
2678 public static void LoadLevel(string levelName)
2679 {
2680 networkingPeer.SetLevelInPropsIfSynced(levelName);
2681
2682 PhotonNetwork.isMessageQueueRunning = false;
2683 networkingPeer.loadingLevelAndPausedNetwork = true;
2684 Application.LoadLevel(levelName);
2685 }
File name: GameManagerScript.cs
Copy
56 public void pauseGame () {
57 pausePanel.SetActive (true);
58 bestScore.text = "Best Score: " + PlayerPrefs.GetInt ("bestScore");
59 highCoinScore.text = "Best Coin Score: " +PlayerPrefs.GetInt ("bestCoinScore");
60 Time.timeScale = 0f;
61 }
File name: GameManagerScript.cs
Copy
63 public void resumeGame () {
64 pausePanel.SetActive (false);
65 scoreText.text = "Score: " + PlayerMoveScript.instance.scoreCount;
66 Time.timeScale = 1f;
67 }
File name: GameManagerScript.cs
Copy
69 public void playAgain () {
70 Time.timeScale = 1f;
71 pauseButton.gameObject.SetActive (true);
72 SceneManager.LoadScene ("Gameplay");
73 gameOverPanel.SetActive (false);
74 }
File name: GameManagerScript.cs
Copy
88 public void gameOver (int score, int coins) {
89 coinScore.gameObject.SetActive (false);
90 pauseButton.gameObject.SetActive (false);
91 gameOverPanel.SetActive (true);
92 gameOverBestScore.text = "Your Score: " + score;
93 gameOverHighCoinScore.text = "Your Coin Score: " + coins;
94
95 }
File name: GameplayController.cs
Copy
34 void Update () {
35 if(Input.GetKeyDown(KeyCode.Escape)){
36 PausePanel ();
37 }
38 }
File name: GameplayController.cs
Copy
233 public void ResumeButton(){
234 pausePanel.SetActive (false);
235 Time.timeScale = 1;
236 gameInProgress = true;
237 }
Download file with original file name:Pause
Pause 121 lượt xem
Gõ tìm kiếm nhanh...