ShowLives
How do I use Show Lives
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
59 | public void ShowLives(int lives) | 1 |
110 | ui.ShowLives(lifeCurrent); | 2 |
124 | ui.ShowLives(lifeCurrent); | 3 |
File name: UIgame.cs
Copy
59 public void ShowLives(int lives)
60 {
61 if (lives <= 0)
62 {
63 lifeBar.enabled = false;
64 FailScreen.SetActive(true);
65 return;
66 }
67 else
68 lifeBar.sprite = hearts[lives - 1];
69 }
File name: PlayerControl.cs
Copy
100 void OnTriggerEnter(Collider col)
101 {
102 if (col.tag == "Enemy" || col.tag == "Danger")
103 {
104 GetDamage();
105 }
106 if (col.tag == "Bonus")
107 {
108 sounds.PlaySoundsPlayer(3);
109 GetBonusEffect(col.GetComponent
110 ui.ShowLives(lifeCurrent);
111 col.gameObject.SetActive(false);
112 }
113 }
File name: PlayerControl.cs
Copy
115 public void GetDamage(int damage = 1)
116 {
117 if (immortal)
118 return;
119
120 immortal = true;
121
122 lifeCurrent-= damage;
123
124 ui.ShowLives(lifeCurrent);
125
126 if (lifeCurrent > 0)
127 {
128 sounds.PlaySoundsPlayer(1);
129 StartCoroutine("Immortality");
130 }
131 else
132 {
133 sounds.PlaySoundsPlayer(2);
134 Die();
135 }
136 }
ShowLives 113 lượt xem
Gõ tìm kiếm nhanh...