Hi guys, I'm a little noob with programming and need some help with an issue.
I'm doing an infinity runner 3D space shooter where my character only moves on the Y Up axis and can rotate his spaceship 360 degrees to move left and right like a rocket.
I made a distance script counter where it shows the distance that the player traveled flying upwards when he press the fly button, but **I need some help with only counts the distance if he is "going up"** , because the script still counts the distance even if the ship is flying down or is flying sideways.
So the question is: how to write for the distance counter script only counts meters if the spaceship is flying up?
Here is my script
public class distanceCounter : MonoBehaviour {
Text mtTxt;
[SerializeField]
private float distance;
[SerializeField]
private GameObject player;
[SerializeField]
private float curPos;
void Start ()
{
mtTxt = GetComponent ();
curPos = player.transform.position.y;
}
void Update ()
{
if (TouchControls.startMeters == true)
{
distance += Time.deltaTime * curPos;
}
mtTxt.text = "Meters: " + distance + " m";
}
}
↧