I am very new to unity, and I created a very simple 2d "game" in which a ball falls from a height and lands on platforms. I was successfully able to script the ball in Javascript to move right upon user input. For some reason though, I cannot let the user add force to the left no matter what I try. I know this must be painfully simple and stupid, so many thanks to whoever deigns to answer this. The code is below
Original without force to the left; works perfectly:
#pragma strict
function FixedUpdate () {
if (Input.GetKey ("right"))
rigidbody2D.AddForce(Vector2.right * 10);
}
My failed attempt to implement left movement:
#pragma strict
function FixedUpdate () {
if (Input.GetKey ("right"))
rigidbody2D.AddForce(Vector2.right * 10);
}
function FixedUpdate () {
if (Input.GetKey ("left"))
rigidbody2D.AddForce(Vector2.(0,-1) * 10);
}
Thank you again
↧