2014-10-22 100 views
1
void FixedUpdate() 
{ 
    ///rotate character model if stick is tilted right or left, but only if character is moving in that direction. 
    if (IsInLocomotion() && ((direction >= 0 && horizontal >= 0) || (direction < 0 && horizontal < 0))) 
    { 
     Vector3 rotationAmount = Vector3.Lerp (Vector3.zero, new Vector3 (0f, rotationDegreePerSecond* (horizontal < 0f ? -1f : 1f), 0f), Mathf.Abs); 
     Quaternion deltaRotation = Quaternion.Euler (rotationAmount * Time.deltaTime); 
     this.transform.rotation = (this.transform.rotation * deltaRotation); 
    } 

} 

我的代碼的這一個特定部分給了我一個錯誤。如果有人會碰巧知道它到底有什麼問題,我將非常感激。我似乎在第九行結束時出現Unity錯誤

我不斷收到錯誤

資產/ CharacterControllerLogics.cs(100,58):錯誤CS1502:最好 重載方法匹配 `UnityEngine.Vector3.Lerp(UnityEngine.Vector3,UnityEngine。的Vector3, 浮動)」有一些無效參數

資產/ CHARACT erControllerLogics.cs(100,58):錯誤CS1503:參數 #3' cannot convert方法組「表達鍵入`浮動」

回答

3

你傳遞Mathf.Abs(的方法)向被期待float作爲其第三個參數的方法。也許你應該提供一個值爲Mathf.Abs(其結果將是float)?例如:

Vector3.Lerp (Vector3.zero, new Vector3 (0f, rotationDegreePerSecond * 
    (horizontal < 0f ? -1f : 1f), 0f), Mathf.Abs(42.0)); 
               ^^^^^^ 
+0

DAM!非常感謝你老兄!完全幫助我!我用2f代替了42f,現在它工作了:)))!!!對不起,我喜歡這種類型的東西x) – user3858703 2014-10-22 11:55:55

+0

@ user3858703:嘿,這就是我們在這裏!學習和教學。此外,由於您是新來賓,如果答案爲您提供了正確的解決方案,請務必將其標記爲已回答。乾杯! – 2014-10-22 11:57:33

相關問題