Unity: Creating collision

Objective: We need to create collision between the player, enemies and lasers so that they destroy each other when they collide.

To start we need to create a new void called OnTriggerEnter so that if the object collides with there objects we can trigger something to happen. Then set up the pseudo code.

Now we need to create our if statements and create the conditions but before that for our if statements we will start using tags in unity and creating one for each game object we have right now. You do this by going into the inspector on each game object, then at the top there should be a tag option and add tags for any tags that aren’t there.

Now that we have a reference to the different game objects we can start filling in our if statements. The condition will be if the other tags is player, then we will destroy this game object. We will fill in the damage part of the pseudo code in another article.

Lastly we will add what happens if the laser collides into the enemy. So, just like the other if statement if the other tag is laser, but now if the laser collides with the enemy we want to destroy both game objects. That means there will be two functions to destroy game objects which will be destroy this game object and the other game object.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jake Boere

Jake Boere


I am hard working Game development student learning as much about game development and unity as possible.