Unity3d 如何解决错误CS1525:无效的表达式项';)';在unity 3d游戏引擎中

Unity3d 如何解决错误CS1525:无效的表达式项';)';在unity 3d游戏引擎中,unity3d,3d,Unity3d,3d,使用UnityEngine 公共类玩家运动:单一行为{ 公共浮子移动速度=5f // Update is called once per frame void Update(){ jump(); Vector3 movment = new Vector3(Input.GetAxis("Horizontal"),0f ,0f); transform.position += movment * Time.deltaTime * moveSpeed; } void jump()

使用UnityEngine

公共类玩家运动:单一行为{ 公共浮子移动速度=5f

// Update is called once per frame
void Update(){
    jump();
   Vector3 movment = new Vector3(Input.GetAxis("Horizontal"),0f ,0f);
   transform.position += movment * Time.deltaTime * moveSpeed; 
}
void jump() {
    if (Input.GetButtonDown("jump"))
    gameObject.GetComponent<"RigidBody2D">();AddForce(new Vector2(0f,5f),ForceMode2D.Impulse);
}
//每帧调用一次更新
无效更新(){
跳跃();
Vector3 movement=新的Vector3(Input.GetAxis(“水平”),0f,0f;
transform.position+=movement*Time.deltaTime*moveSpeed;
}
无效跳转(){
if(Input.GetButtonDown(“跳转”))
gameObject.GetComponent();AddForce(新矢量2(0f,5f),ForceMode2D.pulse);
}
}

我有这个代码,我得到错误CS1525:无效的表达式术语') 问题。

if(Input.GetButtonDown(“跳转”)){
gameObject.GetComponent().AddForce(新矢量2(0f,5f),ForceMode2D.Pulse)
}
不需要GetComponent上的报价!而且“;”用于结束一行,在您的情况下使用“.”。

if(Input.GetButtonDown(“jump”)){
gameObject.GetComponent().AddForce(新矢量2(0f,5f),ForceMode2D.Pulse)
}

不需要GetComponent上的报价!而且“;”用于结束一行,在您的情况下使用“.”。

因此,您似乎使用了一个糟糕的IDE来管理代码。IDE应该指出您使用的分号不正确。我建议学习C#和Unity API,因为在字符中使用字符串对C#无效,更不用说Unity了。这里有一些基本的C#问题。因此,您似乎使用了一个糟糕的IDE来管理代码。IDE应该指出您使用的分号不正确。我建议学习C#和Unity API,因为在字符中使用字符串对C#无效,更不用说Unity了。这些都是基本的C#问题。
if (Input.GetButtonDown("jump")) {
gameObject.GetComponent<RigidBody2D>().AddForce(new Vector2(0f,5f),ForceMode2D.Impulse)
}