简体   繁体   English

错误“命名空间不能直接包含字段或方法等成员”我的代码有什么问题? [等候接听]

[英]Error “A namespace cannot directly contain members such as fields or methods” what's wrong with my code? [on hold]

I have been trying to make all these errors go away for a few hours now and i have tried a lot of methods but somehow none are working, i am new to unity and visual studios.Pls help me solve this.我一直在尝试解决所有这些错误 go 几个小时,我尝试了很多方法,但不知何故都没有奏效,我是统一和视觉工作室的新手。请帮我解决这个问题。

I have tried a lot of methods of putting brackets at different places.我尝试了很多将括号放在不同位置的方法。

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    namespace e
    {
        public class Movement2D : MonoBehaviour
        {

        }



        public float movespeed = 5f;
        void Start()
        {

        }
        void Update()
        {
            object p = Jump();
            Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
            transform.position += movement * Time.deltaTime * moveSpeed;
        }
        void Jump()
        {


            if (Input.GetButtonDown("Jump"))
            {
               gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
            }
        }
    }

I think that the problem is the placement of my brackets, but i do not know where to place them.我认为问题在于我的括号的位置,但我不知道在哪里放置它们。 It just keeps on telling me that "A Namespace cannot directly contain members such as fields or methods.它只是不断告诉我“命名空间不能直接包含字段或方法等成员。

If my comment wasn't clear, code should look like this.如果我的评论不清楚,代码应该是这样的。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace e
{
    public class Movement2D : MonoBehaviour
    {
        public float movespeed = 5f;

        void Start()
        {

        }

        void Update()
        {
            object p = Jump();
            Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
            transform.position += movement * Time.deltaTime * moveSpeed;
        }

        void Jump()
        {
            if (Input.GetButtonDown("Jump"))
            {
                gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
            }
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 命名空间不能直接包含成员,如字段或方法? - A namespace cannot directly contain members such as fields or methods? 错误:名称空间不能直接包含诸如字段或方法之类的成员 - Error: A namespace cannot directly contain members such as fields or methods C# 错误:“命名空间不能直接包含字段或方法等成员” - C# Error: "A namespace cannot directly contain members such as fields or methods" Unity报错:命名空间不能直接包含字段或方法等成员 - Unity error message: A namespace cannot directly contain members such as fields or methods 错误4名称空间不能直接包含成员,例如字段或方法 - Error 4 A namespace cannot directly contain members such as fields or methods 错误“名称空间不能直接包含字段或方法之类的成员”是什么意思? - What does error “A namespace cannot directly contain members such as fields or methods” mean? C# 代码显示错误“命名空间不能直接包含成员,如字段或方法” - C# code showing error "A namespace cannot directly contain members such as fields or methods" “名称空间不能直接包含诸如字段或方法之类的成员” File:具有上下文的控制器 - “A namespace cannot directly contain members such as fields or methods” File: controller with context C#名称空间不能直接包含诸如void的字段或方法之类的成员 - C# A namespace cannot directly contain members such as fields or methods for void 命名空间不能直接包含字段或方法等成员。 - A namespace cannot directly contain members such as fields or methods.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM