簡體   English   中英

錯誤“命名空間不能直接包含字段或方法等成員”我的代碼有什么問題? [等候接聽]

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

我一直在嘗試解決所有這些錯誤 go 幾個小時,我嘗試了很多方法,但不知何故都沒有奏效,我是統一和視覺工作室的新手。請幫我解決這個問題。

我嘗試了很多將括號放在不同位置的方法。

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

我認為問題在於我的括號的位置,但我不知道在哪里放置它們。 它只是不斷告訴我“命名空間不能直接包含字段或方法等成員。

如果我的評論不清楚,代碼應該是這樣的。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM