- Home /
turret not getting destroyed
hello (just to let you know i'm a newbie)
i am making a game where you have to shoot at turrets but every time i shoot at turret it wont get destroyed!
here is my coding! #pragma strict
function OnTriggerEnter(hit : Collider)
{
if (hit.gameObject.tag == "wormBullet")
{
Destroy (hit.gameObject);
Destroy (gameObject);
}
}
and here is pic of my turrets properties! http://imgur.com/TnhGo,c2zos
thanks in advance!!!
Answer by AndyMartin458 · Jan 11, 2013 at 10:07 PM
I'm noticing that you have this script on the top part of the turret. When you run the game in the editor, is this top part of the turret being destroyed while the base remains?
You probably want to put these scripts on the root game object, smallturret.
@Volix OH! I see the problem now. You are using OnTriggerEnter, but under SphereCollider, you have not ticked the Is Trigger box. You'll need to use OnCollisionEnter instead or tick that trigger box (which will keep it from being able to have any physics interactions).
O$$anonymous$$G! it worked! i love you and i will never forget you! THAN$$anonymous$$S!!!
hmm, that makes me think that it is never getting into this part of the code. Have you tried running it in the debugger to ensure this code is being called. Try adding Debug.Log("Called Destroy"); and check the console when you're running the game to see if it called the code. If it didn't then you're problem is that the trigger is not getting triggered.
Your answer
Follow this Question
Related Questions
Scripting error comes up when I press play 1 Answer
NullReferenceException - When destroying Object 1 Answer
Why won't my script load? 1 Answer
Destroyed Object Stops Scipt 1 Answer
Why Can't I Destroy This Object? 4 Answers