- Home /
 
 
               Question by 
               Patricolo · Jan 25, 2014 at 08:52 AM · 
                variabledestroy object  
              
 
              the object is not destroyed to the preset value
Hello to all! I ask in advance sorry for my bad English (I use google translate: () I would like to know why the value of the variable object is not destroyed
 using UnityEngine;
 using System.Collections;
 
 
 
 public class  des   : MonoBehaviour
 {
     public int vita = 100;
     public GameObject oggetto;
     private void OnCollisionEnter(Collision c )
     {
         vita +=1;// add one value
         if(vita == 5) // if value == 5
         {
         GameObject.Destroy (this.gameObject);// not work
         Instantiate(oggetto, transform.position, Quaternion.identity); // not work 
         }
 
 
 
     }
 }
 
 
 
              
               Comment
              
 
               
              Answer by getyour411 · Jan 25, 2014 at 08:55 AM
Change
 GameObject.Destroy(...)
 
               to
 Destroy(...)
 
               and you might need to change
 this.gameObject
 
               to
 c.gameObject
 
               but not sure - are you trying to destroy the gameobject the script is attached to, or the gameobject that hit the CollisionEnter?
If you wanted to destroy this.gameObject, move the instantiate line above that so it instantiates first before destroying (itself)
ok solved!
the solution?
and that I did not realize that the values increased
every time the projectile was in collision and did not have to make that set the preferred values
Sorry my Bad english
Your answer