About 'Destroy GameObject'!

In this video (objectives)…

  1. Add Block.cs script to our block.
  2. Use the Destroy() method to destroy the block once its hit.
  3. Discuss the option to set arguments for the method.

After watching (learning outcomes)… Destroy our block when the ball hits it.

(Unique Video Reference: 14_BR_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Another question for you:

During this lecture, we had to modify the box collider 2D on our red block, since the sprite pixel size was changed from 256 pixels\game unit to 128 pixels\game unit.

If we use the Transform > Scale option, and change x and y to 2 each, it doubles the sprite size and collider size. Is this a more efficient way of doing this, or is object scale used for something else?

Thanks again,

_Rob

I think this is fine Rob. I tend to avoid mixing my approach when I’m first setting my game up because it can lead to confusion for me - if I use pixel size in one place and then scale in another.

1 Like

Hi, could you perhaps explain the OnCollisionEnter2D method a bit more? Or at least tell me if my understanding is correct?

At ~3:20 you say “When this collision takes place, when something calls this method, this is not calling the method, this is creating the method”, this is a bit confusingly worded. Is OnCollisionEnter2D a method that already exists in Unity, and it is called whenever a 2D collision takes place? And the method we are creating now is just to basically tell the Unity engine to tell us when its been called?

Hey Sean,

Let’s see if I can explain this a bit more.

So a Collision is an event. The Unity engine will trigger this event when, in this example, the ball collides with the block. The engine will then look for and call the OnCollisionEnter2D method on the block.

So we create the method in the script, but we use a name that the Unity engine knows and also knows when to call (on a collision event). So Unity knows for what function to look, but we still have to define what the function has to do by creating it.

Hopes this clears it up a bit for you? If not, please let me know and I’ll try to explain it some more.

Cheers,
Ewoud

2 Likes

Privacy & Terms