the script doesn't work

can you help me with this problem
I have this code to make the player move put it doesn’t work the player didn’t move

public class movement : MonoBehaviour {
    private Rigidbody2D reg;
    public float speed = 10f;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        reg = GetComponent<Rigidbody2D>();
        var newx = 0f;
        var newy = 0f;
        if (Input.GetKey("right")){
            newx = speed;

        }else if (Input.GetKey("lift"))
        {
            newx = -speed;
        }   else if (Input.GetKey("up"))
        {
            newy = speed;
        }
     
        reg.AddForce(new Vector2(newx, newy));
	}
}

I hope i can find the solution for this problem ,hello…

  • What value have you assigned to “speed” in the inspector?
  • Line 17 should say “left” rather than “lift”. But even better would be to use Input.GetKey(KeyCode.LeftArrow)) because that would eliminate the risk of making a typo like this.
  • reg = GetComponent<Rigidbody2D>(); would be best moved into the Start() function for performance reasons.
  • Your code is currently framerate-dependent so will play very differently on a PC compared to a mobile phone, say. To avoid this, you should really only use physics functions like AddForce within FixedUpdate, not Update.

thank you