- Home /
 
              This question was 
             closed Jan 17, 2015 at 05:31 PM by 
             tanoshimi for the following reason: 
             
 
            Duplicate Question
 
               Question by 
               Vyctor17 · Jan 17, 2015 at 05:31 PM · 
                script error  
              
 
              NullReferenceException
my script is returning a error:
 NullReferenceException: Object reference not set to an instance of an object
 RedMinionCollision.OnCollisionEnter (UnityEngine.Collision other) (at Assets/RedTeam/RedMinionCollision.js:18)
 
               the script is this:
 var explosion : GameObject ;
 var Target2 : GameObject ;
 function OnCollisionEnter(other : Collision){
    var contact : ContactPoint = other.contacts[0] ;
    var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal) ;
    var cloneExplode : Transform ;
    if (other.gameObject.tag == "Player"){
        cloneExplode = Instantiate(explosion.transform, contact.point, rot) ;
     HUD.CurHealth = HUD.CurHealth-(30-HUD.FisicalDef);
        Destroy(gameObject);  
    }
    else if (other.gameObject.tag == "BlueTeamMid1" || other.gameObject.tag == "BlueTeamMid2" || other.gameObject.tag == "BlueTeamMid3") {
     other.collider.GetComponent(BlueTurretHealth).actDmg = 10;    
        cloneExplode = Instantiate(explosion.transform, contact.point, rot) ;
        Destroy(gameObject); 
    }
    else if (other.gameObject.tag == "BlueMinion") {
        if (other.collider.GetComponent(BlueMinionHealth).MinionHealth != null){
         other.collider.GetComponent(BlueMinionHealth).MinionHealth = other.collider.GetComponent(BlueMinionHealth).MinionHealth-10;
     }    
        cloneExplode = Instantiate(explosion.transform, contact.point, rot) ;
        Destroy(gameObject); 
    }
 }
 
 function Update(){
     if (Target2){
         gameObject.transform.LookAt(Target2.transform.position);
         transform.position += transform.forward*20*Time.deltaTime;
     }
     else{
         Destroy(gameObject);
     }
 }
 
               how to fix it?
               Comment