[英]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.