Hi there, i’m having a slight problem with part of my code for a game i’m developing.
The basic premise is that an object will intercept another object is within range, quick note is that i’m not using sphere colliders for this purpose as they interfere with lens flare effects.
I have a public variable set up as “Target : Gameobject” andd then
Target = findgameobjectwithtag (“Friendly”)
If (Target.distance < RadarRange)
{
Intercept()
}
If (!Target)
{
Patrol()
}
However, when the object (Friendly) has been destroyed i get a null reference exception and the game slows down to a crawl with then enemy objects just flying off in a straight line and not patrolling. Is there anyway to fix this so that when the target variable is null that the enemy fighters go back to patrolling?
Forgive me for the spelling i’m on my mobile and at work, plus i’ve tried to remember the code as best i can since i don’t have it to hand but i’m sur you can get the basic gist of wht i’m trying to do.
Many thanks
I've also tried if (Target == null) as well
– Supershandy