【问题标题】:Platformer Script error CS1525: Unexpected symbol platformSpeed', expecting(', )',,', ;',[', {', or'Platformer 脚本错误 CS1525:意外符号 platformSpeed'、expecting(', )',,', ;',[', {', or'
【发布时间】:2015-02-07 17:56:12
【问题描述】:

我的代码返回以下错误:

Assets/Scritps/Moving_Platform.cs(13,101): 错误 CS1525: 意外符号 platformSpeed', expecting(', )',,', ;',[', {', or'

在 monodevelop 中,Unity 似乎在读取 new Vector3.right 之后的 * 作为其中的一部分,因为该表达式和后面的 * 都以相同的蓝色突出显示。

这是我的代码:

using UnityEngine;
using System.Collections;

public class Moving_Platform : MonoBehaviour {

public Transform platform;
public Transform startTransform;
public Transform endTransform;
public float platformSpeed = 2; 

void FixedUpdate()
{
    platform.rigidbody.MovePosition(platform.position * new Vector3.right * platformSpeed * Time.fixedDeltaTime);
}
void OnDrawGizmos()
{
    Gizmos.color = Color.green;
    Gizmos.DrawWireCube (startTransform.position, platform.localScale);
    Gizmos.color = Color.red;
    Gizmos.DrawWireCube (endTransform.position, platform.localScale);
}

}

我使用的是最新版本的 Unity,版本 4.6。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    删除Vector.right之前的new

    platform.rigidbody.MovePosition(platform.position * Vector3.right * platformSpeed * Time.fixedDeltaTime);
    

    编辑: 您可能希望将对象从platform.position 移动Vector3.right * platformSpeed * Time.fixedDeltaTime。所以你想用add (+)移动到原来的位置。

    platform.rigidbody.MovePosition(platform.position + (Vector3.right * platformSpeed * Time.fixedDeltaTime));
    

    【讨论】:

    • 当我这样做时,我得到 3 个新错误:Moving_Platform.cs(13,58): error CS0019: Operator *' cannot be applied to operands of type UnityEngine.Vector3' 和 UnityEngine.Vector3', Moving_Platform.cs(13,36): error CS1502: The best overloaded method match for UnityEngine.Rigidbody.MovePosition(UnityEngine .Vector3)' 有一些无效参数,Moving_Platform.cs(13,36): error CS1503: Argument #1' cannot convert object' expression to type `UnityEngine.Vector3' 我把“新”放在那里的原因是因为这似乎可以解决这些错误,但后来给了我另一个错误,第一个发布的错误
    • 不客气。然后,您可以点击左侧的“V”来接受我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多