EnemyBullet
How do I use Enemy Bullet
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: Enemy.cs
Copy
136 void Enemy_01_ShootCircle()
137 {
138 int bulletSpeed = 2;
139
140 GameObject bullet = pools.GetPoolableObject("e_bullet");
141
142 Vector3 direction = new Vector3(0,0,-1);
143
144 //
145 for (int i = 0; i < 32; i++)
146 {
147 bullet = pools.GetPoolableObject("e_bullet");
148 if (bullet == null)
149 {
150 continue;
151 }
152
153 bullet.SetActive(true);
154 bullet.GetComponent
155
156 //creat circle of bullets
157 if (direction.x < 1 && direction.z == -1)
158 direction.x += 0.25f;
159 else if (direction.z < 1 && direction.x == 1)
160 direction.z += 0.25f;
161 else if (direction.x > -1 && direction.z == 1)
162 direction.x -= 0.25f;
163 else if (direction.x == -1 && direction.z > -1)
164 direction.z -= 0.25f;
165 }
166 }
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 }
Download file with original file name:EnemyBullet
EnemyBullet 96 lượt xem
Gõ tìm kiếm nhanh...