Skip to content

Instantly share code, notes, and snippets.

@tsweeper
Created February 19, 2020 23:23
Show Gist options
  • Save tsweeper/1ae1f1e5cfdcf87430de9fa41197eb74 to your computer and use it in GitHub Desktop.
Save tsweeper/1ae1f1e5cfdcf87430de9fa41197eb74 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class SpeedLabelSetter : MonoBehaviour
{
private Text _text;
public int valueIndex = 3;
private readonly float[] _values = {
0.7f,
0.8f,
0.9f,
1.0f,
1.1f,
1.2f,
1.3f
};
private void Start()
{
_text = gameObject.GetComponent<Text>();
}
public void SetValueIncrease()
{
valueIndex++;
if (valueIndex > _values.Length - 1) valueIndex = _values.Length - 1;
_text.text = _values[valueIndex].ToString("0.0") + "x";
}
public void SetValueDecrease()
{
valueIndex--;
if (valueIndex < 0) valueIndex = 0;
_text.text = _values[valueIndex].ToString("0.0") + "x";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment