Move Script Help

He. I’ve been trying to learn how to script. Anyway, I need some help. I wrote a script to make my character move left and right for a side scroller. It works, but when I hit the buttons I set up to make the player move, he won’t keep moving if I hold the button down. It only moves once per press. Can someone help me with this?
Here is the script that I’m using:

var moveSpeed = 10;

function Update () {
if(Input.GetButtonDown(“a”)){
transform.position.x += moveSpeed * Time.deltaTime;
}

if(Input.GetButtonDown(“d”)){
transform.position.x -= moveSpeed * Time.deltaTime;
}
}

I am new to this but I think you should use GetButton instead of GetButtonDown

thanks .Samuel. that solved the similar problem I was having :wink:

It would be better to use GetAxis.

transform.position.x += Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

Then you get all of the input manager functionality (snap, gravity, etc.) “for free” without having to do any extra coding.

–Eric