How to make an object disappear when you enter a collider in unity.

Hey guys, how would i make a 3D model disappear when i enter a collider, and also play a sound when the 3d model disappears?

If you need any further questions, feel free to ask.
Thanks :slight_smile:

This should help with the collider.

There are several parts to that task, so let’s unpack the steps for you to look up each step:

  1. Code responds when the collider is entered.
  2. Make an object disappear.
  3. Play a sound.

Step 1 is mostly what Ian said: set the collider as a Trigger, and then give it a script with an OnTriggerEnter() method. Step 2 first requires you to get a reference to the object (there are multiple ways to do that) and then either Destroy it or set Active=false. Step 3 also requires a reference in the script, this time to the AudioClip, and then Play() or PlayOneShot()

(btw my book Unity in Action covers all this if you want to check it out)

1 Like