LIFE
How do I use L I F E
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
35 | lifeMax = 2; | 1 |
80 | life = lifeMax; | 2 |
94 | life -= damage; | 3 |
18 | StartCoroutine("BulletLifeTime"); | 4 |
43 | IEnumerator BulletLifeTime() | 5 |
63 | lifeBar.enabled = false; | 6 |
35 | lifeCurrent = lifeMaximum; | 7 |
110 | ui.ShowLives(lifeCurrent); | 8 |
122 | lifeCurrent-= damage; | 9 |
154 | case (BonusesEnum.bonusHealth): IncreaseCurrentLifeByBonus(); break; | 10 |
File name: Enemy.cs
Copy
30 void Start()
31 {
32 if (enemyType != 0 && enemyType != 4)//not a boss or not a boss ring
33 {
34 if (SystemScr.difficultyIsHard)
35 lifeMax = 2;
36 else
37 lifeMax = 1;
38 }
39
40 life = lifeMax;
41 }
File name: Enemy.cs
Copy
66 public void Activation(Vector3 revealPosition, Vector3 _moveDirection)
67 {
68 transform.position = revealPosition;
69
70 if (enemyType == 2)
71 {
72 moveDirection = _moveDirection;
73 movingSpeed = 2;
74 }
75 else if (enemyType == 3)
76 {
77 movingSpeed = 1.2f;
78 }
79
80 life = lifeMax;
81
82 ShootingStart();
83 }
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
14 public void ShootMe(Vector3 startPos, Vector3 dirrection, float speed = 7)
15 {
16 transform.position = startPos;
17 rb.velocity = dirrection * speed;
18 StartCoroutine("BulletLifeTime");
19 }
File name: EnemyBullet.cs
Copy
43 IEnumerator BulletLifeTime()
44 {
45 yield return new WaitForSeconds(10);
46 BulletIsOff();
47 }
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
32 void Start ()
33 {
34 maxBulletsOnScreen = 1;
35 lifeCurrent = lifeMaximum;
36 speedCurrent = 7;
37 }
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 }
File name: PlayerControl.cs
Copy
148 void GetBonusEffect(BonusesEnum currentBonus)
149 {
150 switch (currentBonus)
151 {
152 case (BonusesEnum.bonusMoney): IncreaseScoreByBonus(); break;
153 case (BonusesEnum.bonusBullet): IncreaseBulletsByBonus(); break;
154 case (BonusesEnum.bonusHealth): IncreaseCurrentLifeByBonus(); break;
155 case (BonusesEnum.bonusSpeed): IncreaseSpeedByBonus(); break;
156 }
157
158 }
Download file with original file name:LIFE
LIFE 140 lượt xem
Gõ tìm kiếm nhanh...