lookat() function cause crash (ios, javascript)

Hi,
I have a big issue and I need help.
In my game I have an airplane which fires missiles at the enemy which isinside a certain area of crosshair. so the player uses SendMessage() to sends the name of the enemy aircraft to the “heat seeking missile” and the HS missile uses the transform.LookAt() function to follow the enemy aircraft.
The issue is that when the player fires two missile at the same time. When the first missile hits and destroys the enemy aircraft, the second missile generate a “null reference error” (It is because the enemy is destroyed and there is not such enemy name in the scene), The confusing thing is that I used a condition for the HS missile to follow an enemy if it is not null:

//receivedEnemy name is a String which is received from the player.
//I used these forms as well: if (receivedEnemyName != null) and if (receivedEnemyName != "" )
//but neither fixes the error!

if ( receivedEnemyName )
{
`     transform.LookAt(GameObject.Find(receivedEnemyName ).transform.position);
}
else
{
`     transform.LookAt(GameObject.Find("terrain").transform.position); // if no enemy is received, then lookat the terrain object which always exists
}

But that doesn’t solve the problem and whenever the second missile generates the error, the app crashes on ios. Any idea?
P.S. All these codes are inside the Update() function.

But you’re not checking if the enemy is null, you’re checking if the receivedEnemyName is null. Destroying the enemy won’t erase its name. You’re then searching for the enemy and using the returned value without first checking that it’s valid.

Also, as a heads up, doing a Find(…) in the Update loop is a pretty bad idea for performance. It won’t matter much while you’re developing small things on PC unless you do it a lot, but it’s a bad habit to be in. What you want to do is use Find when the missile is fired and store a local reference to the GameObject it returns. Then, each frame, if that reference is not null call LookAt(…).