C# Unity“成员修饰符”public“必须在成员类型和名称”error“之前
所以我对编程还不熟悉,我试图找出如何编程运动,但它一直说我有一个错误 成员修饰符public必须位于成员类型和名称之前 这是我的代码,如果你能告诉我如何改进编码学习C# Unity“成员修饰符”public“必须在成员类型和名称”error“之前,c#,unity3d,C#,Unity3d,所以我对编程还不熟悉,我试图找出如何编程运动,但它一直说我有一个错误 成员修饰符public必须位于成员类型和名称之前 这是我的代码,如果你能告诉我如何改进编码学习 public class playerMoment : MonoBehaviour { // Start is called before the first frame update public class ThirdPersonMoment : MonoBehavior {expected
public class playerMoment : MonoBehaviour
{
// Start is called before the first frame update
public class ThirdPersonMoment : MonoBehavior {expected
public Rigidbody Rb;
public CharacterController controller;
public float speed = 6f;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("horizontal");
float vertical = Input.getAxisRaw("vertical");
}
}
错误在这一行公共类ThirdPersonMoment:MonoBehavior{expected
这将导致下一个错误
Member modifier 'public' must precede the member type and name
编译器无法确定预期的内容
由于您还缺少expected之后的半列,编译器假定expected public int Rb;是一条指令,它抱怨您提供的错误-
该错误的原因是因为public-访问修饰符read必须位于定义中的任何其他内容之前
正如在评论中指出的,代码缩进很差——因为您是编程和编码新手——我强烈建议您学习一些基本的代码编写技能,也许还可以学习一些C语言
下面是一个代码示例:
public class PlayerMoment
{
// Start is called before the first frame update
public class ThirdPersonMoment
{
//expected changed into a comment
public int Rb;
public int Controller;
public float Speed = 6f;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("horizontal");
float vertical = Input.getAxisRaw("vertical");
}
}
}
欢迎使用Stack Overflow。请使用和阅读以及其中链接的页面。如果您接受此处列出的建议,您将对Stack Overflow有更好的体验。请删除或定义属性,这应该是可以的。此外,如果您修复缩进和d空格,并使用一致的模式作为开头大括号,或者将所有{在新的一行上,这是c最常见的,或者将它们都放在类/方法声明的同一行上,我投票重新打开,因为发布的代码显示了问题指定的错误消息,假设我们正在使用Unity游戏引擎。
public class PlayerMoment
{
// Start is called before the first frame update
public class ThirdPersonMoment
{
//expected changed into a comment
public int Rb;
public int Controller;
public float Speed = 6f;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("horizontal");
float vertical = Input.getAxisRaw("vertical");
}
}
}