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.