INTERACTIVITY: Asteroids
Starting off this workshop, we created a new script to destroy an object upon contact.
The script at the beginning looked like this:
However, since the OnTriggerEnter is checking for all collisions, the asteroid dissapears instantly. To fix this the script was modified as so:
also for this script to work we added a tag to the asteroid object
to create an explosion we further modified the script using the Instantiate function, and added an if to check weather the player is colliding with the asteroid or not:
now to make the asteroids spawn multiple times we added to the script
also to loop the waves the script was further modified
The script at the beginning looked like this:
However, since the OnTriggerEnter is checking for all collisions, the asteroid dissapears instantly. To fix this the script was modified as so:
also for this script to work we added a tag to the asteroid object
to create an explosion we further modified the script using the Instantiate function, and added an if to check weather the player is colliding with the asteroid or not:
After we checked that the asteroid is working as it should, we made a prefab with it and deleted the original object from the game.
We then went on to create an empty game object to use as a Game Controller.
We added as script to that to spawn the asteroid in the game
Although this spawns the asteroid in, since there are no position values set it defaults to 0,0,0
By doing this the asteroid spawns on top of the ship, therefore causing both to... spontaneously combust o.O
Ship goes boom :P |
The next step is setting a boundary and positions for the asteroid to spawn in off screen.
To do this we modified the script to this:
now to make the asteroids spawn multiple times we added to the script
also to loop the waves the script was further modified
0 comments: