ShootMe









How do I use Shoot Me
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().ShootMe(transform.position, direction.normalized, bulletSpeed);
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().ShootMe(transform.position, new Vector3(0, 0, -1).normalized, bulletSpeed);
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().ShootMe(transform.position, (player.position - transform.position).normalized, bulletSpeed);
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().ShootMe(transform.position, direction.normalized, bulletSpeed);
252
253             }
254         }
255     }
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: PlayerBullet.cs Copy
14     public void ShootMe(Vector3 startPos)
15     {
16         PlayerControl.maxBulletsOnScreen--;
17         transform.position = startPos;
18         rb.velocity = new Vector3(0,0,1 * speed);
19     }
File name: PlayerControl.cs Copy
49     void ShootOrPauseControls()
50     {
51         if (!SystemScr.paused)
52         {
53             if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
54             {
55                 GameObject p_bullet = pools.GetPoolableObject("p_bullet");
56
57                 if (p_bullet != null && maxBulletsOnScreen > 0)
58                 {
59                     sounds.PlaySoundsPlayer(0);
60                     p_bullet.SetActive(true);
61                     p_bullet.GetComponent().ShootMe(transform.position);
62                 }
63             }
64         }
65         if (Input.GetKeyDown(KeyCode.Escape))
66         {
67             ui.Pause_btn();
68         }
69     }

ShootMe 124 lượt xem

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