Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在 2 秒内简单地从 0 变为 1,而不超过 0 或 1。
Mathf.Clamp(buttonPercent += (0.5f * Time.deltaTime), 0, 1.0f);
这导致我的数字增加到超过 1。
我知道一个简单的方法是做这样的事情
buttonPercent += 0.5f; if(buttonPercent > 1){ buttonPercent = 1; }
...但我很好奇为什么我的钳位方法不起作用。
谢谢!
Mathf.Clamp 返回钳位值并且不会更改输入,因为它是按值调用。
将其更改为:
buttonPercent = Mathf.Clamp(buttonPercent + (0.5f * Time.deltaTime), 0, 1.0f);