I’ve created a basic HUD radar system based on 3D objects (Plane), the script detect the enemy and follow him on screen, but my problem is ,sometimes HUD go to out of the screen area.
Here is my code:
#pragma strict
// ******Public dimentions ******
public var AircraftObject : Transform;
// ******Private dimentions ******
//Fetch CpuScript class to get some varibles
private var mainClass : CpuScript;
private var isRenderer : boolean;
private var aircraftArea : float;
//Other perfabs
private var Spd : GameObject;
private var Alt : GameObject;
private var Trg : GameObject;
//Calculating varibles
private var Distance : int;
private var Speed : int;
function Awake()
{
//Finding all objects
findObjects();
//Set PlayerScript into the mainClass
mainClass = gameObject.GetComponent(CpuScript);
}
function FixedUpdate()
{
isRenderer = mainClass.isProximity;
aircraftArea = mainClass.mainObjectArea;
transform.position.x = aircraftArea / 6;
//Set GUI's
guiControl();
getValue();
}
function guiControl()
{
Spd.GetComponent.<TextMesh>().text = Speed + " Knot";
Alt.GetComponent.<TextMesh>().text = "Enemy detected";
Trg.GetComponent.<TextMesh>().text = Distance + " Ft";
}
function getValue()
{
Distance = Vector3.Distance(AircraftObject.transform.position, mainClass.AircraftDistance) * 4;
Speed = Random.Range(100, 300);
}
function findObjects()
{
Spd = GameObject.Find("Speed");
Alt = GameObject.Find("Alt");
Trg = GameObject.Find("AimTarget");
}