UNITY TUTORIAL | PROJECT | SPACE SHOOTER |12. Spwan Waves

2
instantiating “hazard” inside “for loop” 

 

3
setting public variable “hazard count”

 

ezgif.com-video-to-gif
multiple “hazard”s are instantiated at the same time

 

 

4
using “WaitForSeconds()” to put a pause between every instantiation
5
creating “coroutine” to use “WaitForSeconds()”
6
setting “Game Controller” using “coroutine”

 

ezgif.com-video-to-gif-2
spawning “a” wave

 

7
adding “while loop” to make in

 

ezgif.com-video-to-gif-3.gif
having multiple waves of hazard

 

8
clones of “explosion” animation resting in the game
9.png
using “Destroy()” with “lifeTime” variable to remove useless GameObjects
10
setting destroy timer by selecting multiple components

ezgif.com-video-to-gif-4.gif

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |9. Creating Hazards

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |9. Creating Hazards

2
Adding Asteroid as Hazard

 

3
Adding “RigidBody” and “Capsule Collider”

 

4
adding a script to give Tumbling
5
setting tumbling speed with a public variable
6
RigidBody.AngularVelocity | Random.insideUnitSphere
ezgif.com-video-to-gif
tumbling Asteroid but with Angular Drag
7
setting Angular Drag to 0
ezgif.com-video-to-gif-2
Asteroid tumbling without Angular Drag
8
adding a script to make destruction
9
OntriggerEnter to detect any collision | Destroy()
  • Destroy(other) – only removing the collider
  • Destroy(other.gameObject) – removing only the gameObject with Collider “other”
ezgif.com-video-to-gif-3
Bug | something is triggering “Destroy()” function
10
Debug.Log (other.name)
ezgif.com-video-to-gif-4
Debugging 1 | finding the cause
11
Debugging 2 | finding the cause
12
Debugging 3 | Tagging “Boundary”
13
Debugging 4 | detecting any gameObject with a tag “Bounadry” | return
  • Return ends the execution of a function and hands the control back the function that called it (maybe Unity itself)
  •  Return ends OntriggerEnter Function and returns the control back to Unity’s Game Loop
  • As a result, if the object’s tag is “Boundary”, we will never reach or execute “Destroy” function
ezgif.com-video-to-gif-5
Debugging 6 | Solved
ezgif.com-video-to-gif-6
Asteroid destroyed by Laser

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |8. Boundary

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |8. Boundary

2
Creating “Cube” as Boundary with Collider
3
positioning and scaling “Boundary” along with BackGround
4
Adding a Script for “Boundary”
512.png
Deleting any components of Mesh from “Boundary”

 

6
OnTriggerExit() | Destroy()

 

ezgif.com-video-to-gif

UNITY TUTORIAL | PHYSICS | 3D Physics | RayCasting

UNITY TUTORIAL | PHYSICS | 3D Physics | RayCasting

Casts a ray, from point origin, in direction direction, of length maxDistance, against all colliders in the scene.

Casts a ray against all colliders in the scene and returns detailed information on what was hit.
2
RayCast | Serialized Field
3
Physics.RayCast() | Destroy() | [SerializedField]
ezgif.com-video-to-gif
RayCasting
RayCasting
Debug.DrawRay()

 

ezgif.com-video-to-gif (1).gif
RayCasting | Debug.DrawRay()