Movement script not working

I made a movement script but it’s not working, when i put it on my character and test the game it doesn’t do anything when i try to move (I’m a very new programmer btw)

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {
	public float maxSpeed = 10;
	public float jumpForce = 650;
	public Transform groundCheck;
	private float groundedRadius = .2f;
	private bool grounded = false;
	public LayerMask whatIsGround;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetButtonDown ("Horizontal")) {
			rigidbody2D.AddForce(new Vector2 (maxSpeed, 0f));
		}
		if (Input.GetButtonDown ("Jump") && grounded) {
			rigidbody2D.AddForce(new Vector2 (0f, jumpForce));		
		}
	}

	void FixedUpdate () {
		grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, whatIsGround);
	}
}

Thank you in advance :slight_smile:

Edit: I have partly fixed it, now i can jump. I forgot to tell unity what object the ground check was… I am smart
¨
Edit 2: Thank you for all the help :), but i plan on making my game on a keyboard, not a controller, so Input.GetAxis wouldn’t work (As far as i know)

Check your Input Manager within unity, make sure that your axises are exactly what you typed in code, in this case, it is “Horizontal” and “Jump”. As for jump, you have an additional case, make sure that is also true (because you put the “and” within the case).

Since it’s a 2D game you can make it really simple by just doing this:

if (Input.GetKey (KeyCode.D)) {
     transform.Translate(Vector2.right * maxSpeed * Time.deltaTime);
     transform.eulerAngles = new Vector2 (0, 0);
}

if (Input.GetKey (KeyCode.A)) {
     transform.Translate(Vector2.right * maxSpeed * Time.deltaTime);
     transform.eulerAngles = new Vector2 (0, 180);
}

I would say that your inputs are wrong from my experience, I would put

 if (Input.GetAxis("Horizontal")) {
rigidbody2D.AddForce(new Vector2 (maxSpeed, 0f));
}

Horizonal is not a button but an axis this may help

:slight_smile:

I see that you plan on using the game with keys and not with joysticks, however you can still use Input.GetAxis("Horizontal") or vertical. It will give you float values between -1 and 1 depending on what key is pressed, and how long. Default keys are a and d, or left arrow and right arrow. You can see these in Edit → Project Setting → Input. Then in inspector check the horizontal and vertical, it’ll tell the positive and negative keys. If you don’t want them as float, you should use Input.GetAxisRaw("Horizontal") it’ll be int value so either -1, 0, or 1. In the input inspector you’ll see two Horizontal and Vertical setting and you see their type, would be either Joystick, or Key or Mouse Button. So Unity will use the receptive input even when you use GetAxis().

If you still wanna use the button then, you have to use like Input.GetKeyDown(KeyCode.W).