- Home /
ON hit remove
I have a cube, and when a Sphere hits it I want it to get removed, but it isn't working! I've tried it in C# and Java, but neither will work! Here is my java version:
function OnTriggerEnter(other : Collider){
Destroy(gameObject);
}
and here is my C# version:
using UnityEngine;
using System.Collections;
public class Cube Die : MonoBehaviour {
void OnTriggerEnter () {
Destroy(gameObject);
}
}
Answer by aldonaletto · Jul 22, 2011 at 02:05 AM
I've tested the javascript code and it worked fine. Have you set Is Trigger in the cube collider? Have you attached this script to the cube object? If so, the cube should disappear when some rigidbody or character controller collides with it. One more question: is the sphere a rigidbody or character controller? If it is a character controller, it will not be detected if moved with Translate - only CharacterController's Move or SimpleMove ensures it will be detected.
Your answer
![](https://koobas.hobune.stream/wayback/20220612152729im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Script won't destroy prefab clones... 1 Answer
Distribute terrain in zones 3 Answers
Why are objects just set to null? 2 Answers