How to slow this script down?

I am trying to make a simple game as project for school, and I’m trying to get my sphere to move. Currently, I’m using this script.

if (Input.GetKey(KeyCode.LeftArrow))

{

Vector3 position = this.transform.position;

position.x–;

this.transform.position = position;

}

My only problem is, the sphere keeps shooting all over the place, really fast. I want the movement speed to be slow, but the sphere manages to go off the screen in seconds. How can I slow it down?

Just make it so the x position decreases slower. Here’s a revised script:

var moveSpeed:float = 0.1;

if (Input.GetKey(KeyCode.LeftArrow))
{
    Vector3 position = this.transform.position;
    position.x = position.x - moveSpeed;
    this.transform.position = position;
}

I added a moveSpeed variable to make it easier to change the speed. If this is still too fast, just lower the moveSpeed variable again.

Another note: With this script it may move at different speeds on lower/higher performing computers. I’m not entirely sure this is true, but it’s worth noting. To fix this you’d use “Time.deltaTime” to regulate the movement speed across any framerate.