在 Unity C# 中,如何检测浮点变量是否增加了 10?

我正在 Unity3D 中制作一个跑步游戏,我想检测每次距离(浮动变量)增加 10 以提高一点速度,这可能吗???提前致谢 :)


沧海一幻觉
浏览 257回答 1
1回答

浮云间

好吧,感谢@mjwills 很快找到了解决方案!!!这是代码:using System.Collections;using UnityEngine;public class GameManager : SingleTon<GameManager> {&nbsp; &nbsp; private float oldDis;&nbsp; &nbsp; void Start()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; oldDis = distance;&nbsp; &nbsp; }&nbsp; &nbsp; // Update is called once per frame&nbsp; &nbsp; void Update ()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (distance - oldDis >= 10)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug.Log("Raised up by 10 and now it's " + distance + " !!!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldDis = distance;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP