Unity "member modifier "公共" must precede the member type and name"错误



所以我是编程新手,我试图找出如何对机芯进行编程,但它一直说我有一个错误

"成员修饰符";"公共";必须在成员类型和名称之前

如果你能告诉我如何在学习编码方面有所改进,这也是我的代码

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");
    }
}

错误在public class ThirdPersonMoment : MonoBehavior {expected 这一行

the name 'expected' does not exist in the current context. 

这导致下一个错误

Member modifier 'public' must precede the member type and name   

编译器无法确定expected是什么。

由于您还缺少expected之后的半列,因此编译器假定expected public int Rb;是一条指令-抱怨您提供的错误-

该错误的原因是public-访问修饰符(在此处读取(必须位于定义中的任何其他内容之前。

正如评论中所指出的,代码的缩进很差——因为你是编程和编码的新手——我强烈建议你学习一些基本的代码编写技能,也许还可以学习更多关于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");
            }
        }
    }

相关内容

最新更新