GetDamage









How do I use Get Damage
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Enemy.cs Copy
91     public void GetDamage(int damage = 1)
92     {
93         sounds.PlaySoundsEnemy();
94         life -= damage;
95         if (life < 1)
96             Die();
97     }
File name: EnemyBullet.cs Copy
29     void OnTriggerEnter(Collider col)
30     {
31         if (col.tag == "Player")
32         {
33             col.GetComponent().GetDamage();
34         }
35     }
File name: PlayerBullet.cs Copy
29     void OnTriggerEnter(Collider col)
30     {
31         if (col.tag == "Building")
32         {
33             BulletIsOff();
34         }
35         else if (col.tag == "Enemy")
36         {
37             col.GetComponent().GetDamage();
38             BulletIsOff();
39         }
40     }
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().thisBonus);
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     }

GetDamage 112 lượt xem

Gõ tìm kiếm nhanh...