Platformer 脚本错误 CS1525:意外的符号 platformSpeed', expecting(', )',', ;',[', {', or'

Platformer Script error CS1525: Unexpected symbol platformSpeed', expecting(', )',,', ;',[', {', or'

我的代码返回以下错误:

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

在 modevelop 中,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。

去掉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));