GameDev : revert project from 3D to 2D (Part III)

We have to set up the Collisions, becuase without them our Game is really bad!
In the “old” Enemy we had RigidBody and BoxCollider.
The only problem was that these Components worked in 3D, but not in 2D.
In Unity we have same components, but for 2D and 3D.

Here we need a RIGIDBODY 2D and a BOX COLLIDER 2D.
In Enemy Inspector, we add

We add Box Collider 2D and Rigidbody 2D

We need to set the Gavity Scale on Rigidbody 2D to 0, and check the toogle “Trigger” on Box Collider 2D.

We also need Box Collider 2D on Player.

If we look at the Collider on Player

It’s a little too big.
To edit it, go to the Inspector and in the 2D Box Collider look for “Edit Collider”.
If we press it, we can now directly manage size of Collider.

We can also Zoom in with mouse wheel to be more precise

And we make the same for Enemy

Because I manage the Enemy from Scene, I have to click “OVERRIDE” and “APPLY ALL” to modify every instance of Prefab!

Now I can delete Enemy from my Scene and test it

And does’t work….
Why?

We open Enemy script and we see what is the problem…

We have this…
But exactly as for Components, we need a 2D VERSION OF TRIGGER ENTER METHOD!

To change it, we simply add the 2D keyword

And we pass the 2D COLLIDER as Parameter

I forgot to change tag from Untagged to Player, and I change now

Test it

It works great, we have good 2D Sprite Art for Enemy and Player, we have a background and the collisions work.
We only need the Laser.

For the laser, I completely rebuild it.
I take my Laser Sprite and drop into the Scene

I set its scale to 0.2, add Rigidbody 2D and Box Collider 2D and modify the Collider as I did with Enemy and Player.
I set Layer on ForeGround and check the Trigger into Box Collider

Delete the old Laser and make this a prefab

Drag the Laser into Player Inspector

And reset the tag to Laser

Final test

And everything works fine!

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!