I am making a Space Sim. Right now, my ship can boost, increase it’s speed, and decrease it’s speed. What I need is a GUI of some sort that shows the increase or decrease of speed. I’m not sure how to do that. Here’s my speed script:
var defaultSpeed = 50.0; // speed to default towards if no keys are pressed
var maxSpeed = 75.0;
var minSpeed = 25.0;
var maxAcceleration = 5.0; // Controls the acceleration
var currentSpeed = 50.0;
// var Player = transform; // this line gave me an error and it isn't needed any way
function Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * currentSpeed);
if(Input.GetKey("up"))
currentSpeed += maxAcceleration * Time.deltaTime;
else if(Input.GetKey("down"))
currentSpeed-=maxAcceleration * Time.deltaTime;
else if (currentSpeed > defaultSpeed){
currentSpeed -= maxAcceleration * Time.deltaTime;
currentSpeed = Mathf.Clamp(currentSpeed, defaultSpeed, maxSpeed);
}
else {
currentSpeed += maxAcceleration * Time.deltaTime;
currentSpeed = Mathf.Clamp(currentSpeed, minSpeed, defaultSpeed);
}
currentSpeed = Mathf.Clamp(currentSpeed, minSpeed, maxSpeed);
}
The current speed always updates itself in the inspector when I speed up, or slow down, so the current speed is what I want to show. I’m not sure how to show that in GUI, so help would be greatly appreciated. Thanks in advance.