错误 CS1022:类型或命名空间定义,或文件结尾预期的 Unity 3D 游戏引擎



我有这个脚本文件

using UnityEngine;
public class playermove : MonoBehaviour{
public float moveSpeed=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);
}
}
}

我收到此错误:

错误 CS1022:类型或命名空间定义,或预期的文件结尾 Unity 3D 游戏引擎

您的编码文件存在括号问题。

public float moveSpeed=5f;}

它应该是这样的:

using UnityEngine;
public class playermove : MonoBehaviour
{
public float moveSpeed = 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);
}
}

最新更新