This question was
closed Feb 02, 2019 at 05:34 PM by
LegendaryCreator for the following reason:
The question is answered, right answer was accepted
Question by
LegendaryCreator · Feb 08, 2017 at 05:33 PM ·
colliderplayer
I have a gameobject with a box collider using c# how do i destroy it when the player touches it?
untitled.png
(306.8 kB)
Comment
add a script to the object, use OnCollisionEnter, check if it's the player, destroy
Answer by Joeltron · Feb 08, 2017 at 07:43 PM
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
the example there is almost exactly what you want.
just need to change it to:
public class ExampleClass : MonoBehaviour {
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Player"){
Destroy(gameObject);
}
}
}