StartGame
How do I use Start Game
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: BallControl.cs
Copy
31 void RestartGame() {
32 ResetBall ();
33 Invoke ("GoBall", 1);
34 }
File name: GameManager.cs
Copy
27 void OnGUI() {
28 GUI.skin = layout;
29 GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "" + PlayerScore1);
30 GUI.Label (new Rect (Screen.width / 2 + 150 + 12, 20, 100, 100), "" + PlayerScore2);
31
32 if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESTART")) {
33 PlayerScore1 = 0;
34 PlayerScore2 = 0;
35 theBall.SendMessage ("RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
36 }
37
38 if (PlayerScore1 == 10) {
39 GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER ONE WINS");
40 theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
41 } else if (PlayerScore2 == 10) {
42 GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
43 theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
44 }
45 }
File name: SideWalls.cs
Copy
7 void OnTriggerEnter2D(Collider2D hitInfo) {
8 if (hitInfo.name == "Ball")
9 {
10 string wallName = transform.name;
11 GameManager.Score (wallName);
12 hitInfo.gameObject.SendMessage ("RestartGame", 1, SendMessageOptions.RequireReceiver);
13 }
14 }
File name: GameManagerScript.cs
Copy
44 public void RestartGame () {
45 StartCoroutine ("RestartGameCoroutine");
46 }
File name: GameManagerScript.cs
Copy
48 public IEnumerator RestartGameCoroutine() {
49 player.gameObject.SetActive (false);
50 yield return new WaitForSeconds (0.5f);
51 player.transform.position = playerStartPoint;
52 groundGenerator.position = groundStartPoint;
53 player.gameObject.SetActive (true);
54 }
File name: UIstart.cs
Copy
39 public void StartGame_btn()
40 {
41 SceneManager.LoadScene("GameScene");
42 }
File name: GameplayController.cs
Copy
242 public void RestartGame(){
243 SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
244 if(GameController.instance != null){
245 GameController.instance.currentLevel = prevLevel;
246 }
247 }
File name: GameManager.cs
Copy
66 public void RestartGame() {
67 SceneManager.LoadScene("Gameplay");
68 }
File name: TutorialInfo.cs
Copy
32 void Awake()
33 {
34 // have we already shown this once?
35 if(alreadyShownThisSession)
36 {
37 StartGame();
38 }
39 else
40 {
41 alreadyShownThisSession = true;
42
43 // Check player prefs for show at start preference
44 if (PlayerPrefs.HasKey(showAtStartPrefsKey))
45 {
46 showAtStart = PlayerPrefs.GetInt(showAtStartPrefsKey) == 1;
47 }
48
49 // set UI toggle to match the existing UI preference
50 showAtStartToggle.isOn = showAtStart;
51
52 // show the overlay info or continue to play the game
53 if (showAtStart)
54 {
55 ShowLaunchScreen();
56 }
57 else
58 {
59 StartGame ();
60 }
61 }
62 }
File name: TutorialInfo.cs
Copy
80 // and that the audio listener is enabled, and time scale is 1 (normal)
81 public void StartGame()
82 {
83 overlay.SetActive (false);
84 mainListener.enabled = true;
85 Time.timeScale = 1f;
86 }
Download file with original file name:StartGame
StartGame 120 lượt xem
Gõ tìm kiếm nhanh...