# How do I make an object take just 1 step (not continues movement)

I am making a game with 3 buttons and if you press one if these buttons with your mouse I want an object to take 1 step on the X position (either left or right doesn’t matter)
and all I can find is continues movement moving an object from A to B etc but that is not what I need so any help would be greatly appreciated ^^.

You can set your position manually if you don’t need it to be a gradual transition. Just use transform.position to update the object’s position.

``````//Move object +1 unit in the x direction
transform.position += new Vector3(1f, 0, 0);
``````

using UnityEngine;

``````public class MoveCube : MonoBehaviour {

void Update () {

if (Input.GetKeyDown (KeyCode.A)) {
transform.position = transform.position + Vector3.left;
}
if (Input.GetKeyDown (KeyCode.D)) {
transform.position = transform.position + Vector3.right;
}
}
}
``````

or

``````using UnityEngine;
using System.Collections;

public class MoveCube : MonoBehaviour {

public float moveSpeed = 0.5f, t;
bool canMove = true;
void Update () {

if (Input.GetKeyDown (KeyCode.A) && canMove) {
StartCoroutine(Move (transform.position + Vector3.left));
canMove = false;
}
if (Input.GetKeyDown (KeyCode.D) && canMove) {
StartCoroutine(Move (transform.position + Vector3.right));
canMove = false;
}
}
IEnumerator Move(Vector3 dir){
t = 0.0f;
while (t < moveSpeed) {
t += Time.deltaTime;
transform.position = Vector3.Lerp (transform.position, dir, t / moveSpeed);
yield return new WaitForEndOfFrame ();
}
canMove = true;
}
}
``````