I need to make The Score for a slope style game but mine has levels almost like geometry dash and the score I have is counting up by the players z position but I was wondering How to make this a percentage that counts up 1-100
So the level progresses the further you go along the z-axis? If you know the maximum value of z when the level is finished, you could use the min z (Iām assuming this would be 0) and max z and current z to calculate the percentage right? Sorry if I have misunderstood.
If you have this script on your moving player:
using UnityEngine;
public class PercentageCalc : MonoBehaviour
{
float startZ = 100f; // Start has to be lower than end
float endZ = 240f; // End has to be higher than start
float currentPercentage;
private void Update()
{
currentPercentage = (transform.position.z - startZ) / (endZ - startZ) * 100f;
// You can do this to only get int percentage
currentPercentage = (int)((Mathf.Clamp01(currentPercentage / 100f) * 100f));
}
}
You can read the value currentPercentage and update UI with it.
This seems to be working great but I need it to show this percentage in score text script which currently has scoreText.text = player.position.z.ToString(ā0ā); which just updates the players position to the score text