day 13

Oksana Vasquez
1 min readDec 17, 2020

today I worked with “Enemy section”

I solved Challenge Review Enemy Behavior and while doing it I learned how to use Random.Range(-xf, xf) to set a random number between -x and x. Pretty cool!

In Unity there are two types of collision.

I order to collide we need to enable physic system of Unity through Rigid Body.

Hard surface collision = ball bouncing back from the wall

Trigger collision = Mario collecting coins = passing through the object and collecting something, illusion of colliding. (Box Collider In Trigger check). In our example we want to use Trigger collision. Just an illusion of collision.

We also need a Rigid Body

We can check in API Scripting Monobehaviour we can look up OnTriggerEnter method. For this method to work of two objects must have a Rigid Body.

In our game Laser and Enemy collide with Player.

In Capsule Collider of the Laser I check In Trigger like I did it with enemy. I also add Rigid Body to Laser but uncheck Gravity here because we don’t need Laser to fall. We do the same to the Enemy.

Now we want to detect players in Enemy script so we will use OnTriggerEnter here.

In Unity we have tags which let us define objects. And once objects have tags we can detect them through the tag. To figure out how? That is a hint. I need to google how to detect objects using their tags.

--

--