ShootingRoutine
How do I use Shooting Routine
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
119 | case 1: StartCoroutine("ShootingRoutine_01"); break; | 1 |
127 | IEnumerator ShootingRoutine_01() | 2 |
169 | IEnumerator ShootingRoutine_02() | 3 |
188 | IEnumerator ShootingRoutine_03() | 4 |
216 | IEnumerator ShootingRoutine_04() | 5 |
File name: Enemy.cs
Copy
115 void ShootingStart()
116 {
117 switch (enemyType)
118 {
119 case 1: StartCoroutine("ShootingRoutine_01"); break;
120 case 2: StartCoroutine("ShootingRoutine_02"); break;
121 case 3: StartCoroutine("ShootingRoutine_03"); break;
122 case 4: StartCoroutine("ShootingRoutine_04"); break;
123 }
124 }
File name: Enemy.cs
Copy
127 IEnumerator ShootingRoutine_01()
128 {
129 for (int i = 0; i < 2; i++)
130 {
131 yield return new WaitForSeconds(1f);
132 Enemy_01_ShootCircle();
133 }
134 }
File name: Enemy.cs
Copy
169 IEnumerator ShootingRoutine_02()
170 {
171 while (true)
172 {
173 int bulletSpeed = 7;
174
175 yield return new WaitForSeconds(2f);
176
177 GameObject bullet = pools.GetPoolableObject("e_bullet");
178
179 if (bullet != null)
180 {
181 bullet.SetActive(true);
182 bullet.GetComponent
183 }
184 }
185 }
File name: Enemy.cs
Copy
188 IEnumerator ShootingRoutine_03()
189 {
190 GameObject tempPlayer = GameObject.FindGameObjectWithTag("Player");
191
192 //if player didnt destroyed
193 if (tempPlayer != null)
194 player = tempPlayer.GetComponent
195 else
196 player = transform;
197
198 GameObject bullet = null;
199 int bulletSpeed = 9;
200
201 while (true)
202 {
203 yield return new WaitForSeconds(1.5f);
204
205 bullet = pools.GetPoolableObject("e_bullet");
206
207 if (bullet != null)
208 {
209 bullet.SetActive(true);
210 bullet.GetComponent
211 }
212 }
213 }
File name: Enemy.cs
Copy
216 IEnumerator ShootingRoutine_04()
217 {
218 yield return new WaitForSeconds(1f);
219 int bulletSpeed = 4;
220
221 GameObject bullet = pools.GetPoolableObject("e_bullet");
222
223 Vector3 direction = new Vector3(0,0,0);
224 int rCount = 1;
225
226 while (true)
227 {
228 if (rCount == 1)
229 {
230 StartCoroutine("ShootingRoutine_01");
231 rCount = 0;
232 }
233 else
234 rCount++;
235
236 yield return new WaitForSeconds(0.3f);
237 for (int i = 0; i < 64; i++)
238 {
239 bullet = pools.GetPoolableObject("e_bullet");
240
241 if (bullet == null)
242 {
243 continue;
244 }
245
246 yield return new WaitForSeconds(0.1f);
247
248 direction = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f));
249
250 bullet.SetActive(true);
251 bullet.GetComponent
252
253 }
254 }
255 }
ShootingRoutine 100 lượt xem
Gõ tìm kiếm nhanh...