I made this little movement script, it’ for a basic 2D platformer but when I use it my “MotionX” Variable will not be set to 0 when I’m not pressing any keys. Please help!!
var motionX : float;
function Start () {
}
function Update () {
if(Input.GetKeyDown("left")) {
motionX = -10;
}
if(Input.GetKeyDown("right")) {
motionX = 10;
}
if(Input.GetKeyUp("right") && Input.GetKeyUp("left")) {
motionX = 0;
}
rigidbody2D.velocity = (Vector2(motionX,0));
}
Sorry for being a bit newbie.