How do I move my 2D object using arrow keys ?

I found a few similar asked questions but the solutions for which gave me errors while compiling.

Also, a code I used to move it using the arrow keys made it move just 1 unit per key press, despite it being in the Update() snippet, which just didn’t make sense to me.
The code I used is as follows:-

using UnityEngine;
using System.Collections;
 
public class Ctrl : MonoBehaviour
 
{
        void Update ()
        {
                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                        Vector3 position = this.transform.position;
                        position.x--;
                        this.transform.position = position;
                }
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                        Vector3 position = this.transform.position;
                        position.x++;
                        this.transform.position = position;
                }
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                        Vector3 position = this.transform.position;
                        position.y++;
                        this.transform.position = position;
                }
                if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                        Vector3 position = this.transform.position;
                        position.y--;
                        this.transform.position = position;
                }
}
}

Thanks for being such a wonderful community !

There is all sorts of different kinds of movements. And there are a bizillion movement scripts posted on UA. So here is a bizillion+1 script:

#pragma strict 

var speed : float = 1.0;

function Update() {
	var move = Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
	transform.position += move * speed * Time.deltaTime;
}

It assumes you’ve left ‘Horizontal’ and ‘Vertical’ axes at their default values. Note your script at the link only moves once because you are use Input.GetKeyDown(). GetKeyDown() returns true for only the frame the button goes down, so you are only getting one movement per keypress. You can ‘fix’ this by changing to Input.GetKey(), which returns true all during the time the key is held down. Note that since you are increment your position by 1 (i.e. using '++"), going to GetKey() will make the object move really fast…likely around 60 units per second.

Probably better to capture whatever Unity uses for a keydown event. I’m actually looking for the way to do that right now, 'cuz it’s apparently different from the standard C# implementation. In 4.6.9, anyway… Haven’t gotten in to 5 yet.

You can use Input.GetKey( ) instead of Input.GetKeyDown( ). It will make a continuous movement.

Thankyou @robertu , i was also looking for the solution to move the player with a simple small script and there i saw your comment which helped me to move my player :smiley: