- Home /
OnTriggerEnter only Destroy other.gameObject.name "?"
Hello World. I'm having trouble creating a simple JavaScript that would destroy only the object with a certain name on collision with an object with a trigger. I have already created a script that should be able to do this, but it doesn't work. The console has no issues with my script, yet it doesn't work. So this is where you come in! Now I figure that if you help me fix my script you will be helping countless others in this subject since this would be useful to others like you, like me. Here is the script noted I'm sorta a noob at programming.
`function OnTriggerEnter (other : Collider) { if(other.gameObject.name == "It"){ Destroy(other.gameObject); } }`
Please Help.
Sincerely, Steven
Answer by SHG · Feb 17, 2013 at 06:12 PM
Here is the finished script it works!
function OnTriggerEnter (other:Collider){
if(other.gameObject.name == "It"){
Debug.Log("It went through");
Destroy(gameObject.Find("It"));
}
}
Answer by digiben · Feb 17, 2013 at 06:59 AM
Steven, did you put a Debug.Log() in there to see if it actually ever gets into the "if" scope? I would print out the name in the debug and see what is coming back in the name variable.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092833im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object being destroyed without GetKey Down 1 Answer
How do I destroy my player on contact? 2 Answers
OnTriggerEnter behaving oddly?!? 1 Answer