2D Touch Player Movement

Ok so I got this error “A namespace cannot directly contain members such as fields or methods”, how can I solve this? Here is the script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerWalk : MonoBehaviour
{
private Rigidbody2D myBody;

private float speed = 2f;

void Start()
{
myBody = GetComponent();
}

// Update is called once per frame
void Update()
{
DetectInput();
}

public void MoveLeft()
{
myBody.velocity = new Vector2(-speed, myBody.velocity.y);

}

public void MoveRight()
{
myBodt.velocity = new Vector2(speed, myBody.velocity.y);
}

public void StopMoving()
{
myBody.Velocity = new Vector2(0f, myBody.velocity.y);
}

}
void DetectInput()
{
float x = Input.GetAxisRaw(“Horizontal”);
if (x > 0)
{
MoveRight();
}
else if (x < 0)
{
MoveLeft();
}
else
{
StopMoving();
}

}

Hi

Its your first post, so - yeah, why not familiarize yourself with the forum etiquette?

Formatting your code blocks correctly:

Also “2D Touch Player Movement” is not a question.

My guess is that you don’t have enough of these curly braces: }

You will need to go through and make sure you have them all. What I think your error message is saying, is that you have a method or constructor living outside of your class. To fix this, insert the } in the correct place. You should have a red squiggly line somewhere in your code. That’s a good place to start looking.

Try to check the syntaxis as it seems to me that the problem is in that field.