target obj null check

As of now I have a homing missile that fires when an enemy object is clicked. I am having an issue once the enemy is destroyed. If I have multiple missiles tracking the same enemy I receive and error when one missile destroys the enemy while others are still tracking it. I tried to check to see if target obj is null and if it is then destroy the missiles but this does not seem to work. I am not sure what I am doing wrong here. This script is attached to the missile.

`var targetObj : Transform;
var shipExplode : Transform;
var lifeTime : float = 5;
var missileSpeed : float = 100;
var enemySound : AudioClip;

function Awake()
{
Destroy(gameObject, lifeTime);
}

function Update ()
{
//this is the code part that I am trying to figure out
//if you can let me know what I am doing wrong that would be great
//the error that I get when after the target is destroyed is
//the object of type ‘Transform’ has been destroyed but you are still trying
//to access it. script should check for if it is null

if(targetObj.transform == null)  
{  
	Destroy(gameObject);  
}  

transform.LookAt(targetObj);
transform.Translate(Vector3.forward * missileSpeed * Time.deltaTime);

}

function OnTriggerEnter()
{
destroyObjects();
}

function destroyObjects()
{
var missilePosition : Vector3 = transform.position;
var shipPosition : Vector3 = targetObj.transform.position;
audio.PlayOneShot(enemySound);

Destroy(gameObject);
Destroy(targetObj.gameObject);
GlobalVars.score++;

var shipClone : Transform;
shipClone = Instantiate(shipExplode, shipPosition, Quaternion.identity);
Destroy(shipClone.gameObject, lifeTime);

}

`

Actually targetObj is a reference to a Transform component. Using `.transform` of a transform is totally useless since it will return the same transform. The problem you encounter is that when the reference is null, you can't access any member variable / properties and that's why you get the error. You have to check the reference itself for being null:

if(targetObj == null) 

Thanks, I thought I tried it early on and it didn't work that's why I added the .transform but it's working now. Here's the finished snippet if anyone else should ever have a mental fail. Thanks again. `

function Update ()    
{
    if(targetObj == null)  
    {  
        print("working");
        Destroy(gameObject);  
    }  
    else  
    {  
        transform.LookAt(targetObj);  
        transform.Translate(Vector3.forward * missileSpeed * Time.deltaTime);  
        var offset : Vector3 = targetObj.position - transform.position;  
    }
}