how to move a 2d object in unity code example
Example: unity 2d how to move square with keyboard
public float speed;
void Update ()
{
// GetAxisRaw is unsmoothed input -1, 0, 1
float v = Input.GetAxisRaw("Vertical");
float h = Input.GetAxisRaw("Horizontal");
// normalize so going diagonally doesn't speed things up
Vector3 direction = new Vector3(h, v, 0f).normalized;
// translate
transform.Translate(direction * speed * Time.deltaTime);
}