Updating display based on GUI slider value

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);

}

**2 things

  1. update the variables after**

vSliderValue = GUI.VerticalSlider (Rect (25, 35, 30, 200), vSliderValue, 85, 0);

RoundedValue = Mathf.Round(vSliderValue);

2. I havn’t tested it yet, but ime pretty sure you can replace

vSliderValue = GUI.VerticalSlider (Rect (25, 35, 30, 200), vSliderValue, 85, 0);
 
 RoundedValue = Mathf.Round(vSliderValue);

| with

vSliderValue : int = GUI.VerticalSlider (Rect (25, 35, 30, 200), vSliderValue, 85, 0);

Thanks for the response.

  1. I understand that updating the variables is what I need to do, but I do not know how to script it. Can anyone help with this?

  2. Good call on this one. I actually had to change the variable definition to

    var vSliderValue : int = 0.0 and then just

    vSliderValue = GUI.VerticalSlider (Rect (25, 35, 30, 200), vSliderValue, 85, 0); was sufficient to give me the integer value that I needed.