public Text txt;
private int num;
private float _timers=10;
private int _target;
public void Set(float index)
{
txt.text = index.ToString();
}
public void Go(int target)
{
_target = target;
num = int.Parse(txt.text);
StopCoroutine("IReduce");
StartCoroutine("IReduce");
}
IEnumerator IReduce()
{
float offset = (num - _target) / _timers;
if (Mathf.Abs(offset) < 1)
{
txt.text = _target.ToString();
yield break;
}
for (int i = 0; i < _timers; i++)
{
num =(int)(num-offset);
txt.text = num.ToString();
if (i == _timers-1)
{
txt.text = _target.ToString();
}
yield return new WaitForSeconds(0.1f);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40