2016-11-20 56 views
1

我想只要從0到1,2秒,不超過0或1爲什麼Mathf.Clamp的這個例子不起作用?

Mathf.Clamp(buttonPercent += (0.5f * Time.deltaTime), 0, 1.0f); 

這將導致增加我的電話號碼過去1

我知道一個簡單的方法是做這樣的事情

buttonPercent += 0.5f; 
if(buttonPercent > 1){ 
    buttonPercent = 1; 
} 

......但我很好奇爲什麼我的鉗位方法不工作。

謝謝!

回答

2

Mathf.Clamp返回鉗位值,不會更改輸入,因爲它是按值調用的。

將其更改爲:

buttonPercent = Mathf.Clamp(buttonPercent + (0.5f * Time.deltaTime), 0, 1.0f); 
+0

謝謝你,這正是它。 – Jim

相關問題