- Home /
Object wont object get destroyed
There is a script on the prefab polly called Destroy that destroys it when it collides with the bullet. the problem is it wont get destroyed and this script is the problem, the Destroy script works fine.
I polly to be destroyed then another one spawns a few seconds later.
Thanks
var polly : GameObject;
function Start () {
}
function Update () {
AttachPolly();
}
function AttachPolly(){
if(transform.childCount <= 0){
var ins : GameObject = Instantiate(polly, transform.position, transform.rotation);
ins.transform.parent = transform;
yield WaitForSeconds(2);
}
}
Answer by Montraydavis · Nov 02, 2012 at 01:18 AM
Add
function OnTriggerEnter ( collision : Collider )
{
if ( collision.tag == "bullet" ) {
GameObject.Destroy ( gameObject ) ;
}
}
Be sure that your trigger is either active on the collider, or change
OnTriggerEnter ( collision : Collider )
if ( collision.tag == "bullet" )
/* to * /
OnCollisionEnter ( collision : Collision )
if ( collision.collider.tag == "bullet" )
//Ensure that you have a rigidbody and collider not set to trigger if you want to use OnCollisionEnter ( ) instead...
If you are not sure about your collision being setup right, check out a Tutorial from YouTube. Otherwise, you should be good to go .
YouTube tutorials: Basic Collisions
I am unsure if you are using a ragdoll or not when you say "polly", so, here is a Ragdoll Physics tutorial.
I hope this helps you resolve your issue.
Thanks for trying to help but the collision works fine. On the Destroy script I told it to debug something after the destroy game object is called and it dose debug. I believe that the problem is right after the object is destroyed another one spawns immediately
Also polly is not a ragdoll. It is just the name of a variable
Great! Please let me know if there is anything else you need assistance with .! :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613083225im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to destroy a object only in game and not the prefab 2 Answers
How to spawn an object continually while floating vertically like a bubble 1 Answer
Losing references after reloading the scene, even though they exist again. 1 Answer
Why not can't spawn the object? 1 Answer
Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer