我创建了一个基于 3D 对象(平面)的基本 HUD 雷达系统,脚本检测敌人并在屏幕上跟随他,但我的问题是,有时 HUD 会超出屏幕区域。
这是我的代码:
#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");
}