I am creating a virtual artillery range and I have a telemetry panel that displays data (Time to impact, Distance to impact, and Maximum height) based on the angle selected by a slider. How do I get the values displayed to update after the slider value (angle) is changed and the projectile is fired? The spacebar is set to fire the projectile in the project settings.
var windowRect : Rect = Rect (15, 15, 245, 420);
static var VelocityInitial = 40;
static var Angle = 0;
static var Rad = Angle*Mathf.Deg2Rad;
static var AccelX = 0;
static var AccelY = -9.8;
static var VelocityInitialX = VelocityInitial*Mathf.Cos(Rad);
static var VelocityInitialY = VelocityInitial*Mathf.Sin(Rad);
static var MaxT = (-VelocityInitialY/AccelY);
static var MaxY = ((VelocityInitialYMaxT) + (0.5AccelY*(Mathf.Pow(MaxT, 2))));
static var ImpactT = (2*MaxT);
static var MaxX = ((VelocityInitialXImpactT) + (0.5AccelX*(Mathf.Pow(ImpactT, 2))));
static var RoundX = (Mathf.Round(10*MaxX)/10);
static var RoundY = (Mathf.Round(10*MaxY)/10);
static var RoundT = (Mathf.Round(100*ImpactT)/100);
var vSliderValue : float = 0.0;
var RoundedValue : float = 0.0;
var GunBarrel : GameObject;
GunBarrel = GameObject.Find(“GunBarrel”);
function OnGUI () {
windowRect = GUI.Window (0, windowRect, WindowFunction, “Telemetry Panel”);
}
function WindowFunction (windowID : int) {
GUI.Box (Rect (50, 115, 135, 25), "Elevation in Degrees");
vSliderValue = GUI.VerticalSlider (Rect (25, 35, 30, 200), vSliderValue, 85, 0);
RoundedValue = Mathf.Round(vSliderValue);
GUI.Box (Rect (92, 145, 55, 25), "" + RoundedValue);
GUI.Button (Rect (50, 235, 145, 25), "Press Spacebar to fire!");
GUI.Box (Rect (10, 285, 225, 25), "Time to impact = " + RoundT + " seconds");
GUI.Box (Rect (10, 335, 225, 25), "Distance to impact = "+ RoundX + " meters");
GUI.Box (Rect (10, 385, 225, 25), "Maximum height = "+ RoundY + " meters");
}
function Update ()
{
GunBarrel.transform.rotation.eulerAngles.x = (90 - RoundedValue);
}