【发布时间】:2021-02-01 18:17:09
【问题描述】:
我正在尝试使“开始游戏”按钮的字体“呼吸”,使用协程增加和减少大小。
字体大小从 2.0 开始,onStart 增大到 2.20(逐渐增加 +0.01 直到达到 2.20)然后回落到 2.0(逐渐减少 -0.01 直到达到 2.0)然后重复。
我的代码在第一部分完美运行,它一直增加到 2.20,但由于某种原因,它没有从 2.20 降低到 2.0。有谁知道我做错了什么?
public class Font_Breathing : MonoBehaviour {
public TMP_Text startGame;
private float change = 0.01f;
private float delay = 0.0f;
void Start()
{
StartCoroutine(IncreaseFont());
}
void Update()
{
}
IEnumerator IncreaseFont()
{
while (startGame.fontSize >= 2.0f)
{
yield return new WaitForSeconds(delay);
startGame.fontSize += change;
if (startGame.fontSize >= 2.20f)
{
StartCoroutine(DecreaseFont());
}
}
}
IEnumerator DecreaseFont()
{
while (startGame.fontSize >= 2.20f)
{
yield return new WaitForSeconds(delay);
startGame.fontSize -= change;
if (startGame.fontSize <= 2.0f)
{
StartCoroutine(IncreaseFont());
}
}
}
}
【问题讨论】: