【问题标题】:I seem to be getting an error in Unity regarding the end of 9th line down关于第 9 行的结尾,我似乎在 Unity 中遇到了错误
【发布时间】:2014-10-22 11:37:35
【问题描述】:
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);
    }

}

我的代码的这一特定部分给了我一个错误。如果有人碰巧知道它到底有什么问题,我将非常感激。

我不断收到错误

Assets/CharacterControllerLogics.cs(100,58):错误 CS1502:最好的 重载方法匹配 `UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' 有一些无效的参数

Assets/CharacterControllerLogics.cs(100,58):错误 CS1503:参数 #3' cannot convertmethod group' 表达式来输入 `float'

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您将Mathf.Abs(一个方法)传递给一个期望float 作为其第三个参数的方法。也许您应该为Mathf.Abs 提供一个值(其结果将是float 类型)?例如:

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

    【讨论】:

    • 大坝!非常感谢老兄!完全帮了我!我用 42 代替了 2f,它现在可以工作了:)))!!!对不起,我对这类东西很陌生 x)
    • @user3858703:嘿,这就是我们来这里的目的!学习和教学。另外,由于您是新来的,如果答案为您提供了正确的解决方案,请确保将其标记为已回答。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多