Code below is my attempt at detecting an hostile ship at radar range but it is not working correctly at the moment. All the help I can get is welcome:smile:
Try makeing one script a Master for the game have it contain all info you want and then when you need to get the list of units/ships in the game acsess it.
What I do is have the list of all units in game, when a unit is spawned it tells the list to add this unit. When a unit dies it removes itself from the master list.
Then when I want to see what units are nere this unit I do a “for loop” though the master list and get the distance for them and if they are nere this unit I add them to a target list that each unit carrys.
When spawning a unit I just put this in Start() on the unit.
You could try something like this. I’m at work so i can’t confirm that the code works or if it’s even typed correctly, but the jift of it’s in there somewhere.
var EnemyTag : String = "Enemy";
var EnemyList : GameObject[];
var Target : GameObject;
var distane : float;
var radardistance : float;
function Update(){
Player = transform.position;
EnemyList = GameObject.FindGameObjectWithTag(EnemyTag);
for(var Enemy : GameObject in EnemyList){
distance = (Enemy.transform.position - Player).magnitude;
}
if(distance < radardistance){
DoSomething(Enemy);
}
}
function DoSomething(Enemy){
}
}