I have an object and I want that with a single press of a button, it goes from point A to point B. In the Update function I created different if statements to test which button is pressed.
In these if statements, I used the GetKeyDown fuction to move the object and it works very well when I hold down a button (the left arrow for example).
But I want the object's translation from point A to point B with a single press of the left button over a certain amount of time. If I use GetKey the object doesn't move from point A to point B automatically, but it moves only of few units.
public class Movement: MonoBehaviour
{
public Transform cube;
public Transform target;
public int speed; //I can change it in the Inspector
void Update()
{
float amtToMove = speed * Time.deltaTime;
if (Input.GetKey("left"))
{
transform.position = Vector3.Lerp(cube.position, target.position, amtToMove);
}
}
}
Sorry for the bad english.
Can anyone help me?