所以我得到了错误代码错误CS1022我只是不知道如何修复它,因为我找不到错误,可能删除了一些东西,因为我很着急



所以我得到了错误代码错误CS1022:类型或名称空间定义,或结束文件预期我只是不知道如何修复它,因为我找不到错误,可能删除了一些东西,因为我在匆忙

代码如下:

使用System.Collections';使用System.Collections.Generic;使用UnityEngine;

public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb;
private Vector2 moveVelocity;
}

void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * speed;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
}  `

在定义方法之前,用括号}关闭class

public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb;
private Vector2 moveVelocity;

void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * speed;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
} 

相关内容