LostALife
How do I use Lost A Life
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
50 | case GameState.LostALife: | 1 |
97 | CurrentGameState = GameState.LostALife; | 2 |
115 | LostALife, | 3 |
File name: GameManager.cs
Copy
27 void Update()
28 {
29 switch (CurrentGameState)
30 {
31 case GameState.Start:
32 if (InputTaken())
33 {
34 statusText.text = string.Format("Lives: {0} Score: {1}", Lives, Score);
35 CurrentGameState = GameState.Playing;
36 Ball.StartBall();
37 }
38 break;
39 case GameState.Playing:
40 break;
41 case GameState.Won:
42 if (InputTaken())
43 {
44 Restart();
45 Ball.StartBall();
46 statusText.text = string.Format("Lives: {0} Score: {1}", Lives, Score);
47 CurrentGameState = GameState.Playing;
48 }
49 break;
50 case GameState.LostALife:
51 if (InputTaken())
52 {
53 Ball.StartBall();
54 statusText.text = string.Format("Lives: {0} Score: {1}", Lives, Score);
55 CurrentGameState = GameState.Playing;
56 }
57 break;
58 case GameState.LostAllLives:
59 if (InputTaken())
60 {
61 Restart();
62 Ball.StartBall();
63 statusText.text = string.Format("Lives: {0} Score: {1}", Lives, Score);
64 CurrentGameState = GameState.Playing;
65 }
66 break;
67 default:
68 break;
69 }
70 }
File name: GameManager.cs
Copy
84 public void DecreaseLives()
85 {
86 if (Lives > 0)
87 Lives--;
88
89 if(Lives == 0)
90 {
91 statusText.text = "Lost all lives. Tap to play again";
92 CurrentGameState = GameState.LostAllLives;
93 }
94 else
95 {
96 statusText.text = "Lost a life. Tap to continue";
97 CurrentGameState = GameState.LostALife;
98 }
99 Ball.StopBall();
100 }
File name: GameManager.cs
Copy
111 {
112 Start,
113 Playing,
114 Won,
115 LostALife,
116 LostAllLives
117 }
LostALife 112 lượt xem
Gõ tìm kiếm nhanh...