Created
February 19, 2020 23:23
-
-
Save tsweeper/1ae1f1e5cfdcf87430de9fa41197eb74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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