How to make a RigidBody move in a certain direction

Hello,

I am trying to make an android game and I am using Unity 5. I am trying to make touch controls for the player to move left and right. I have this:


function Start(){
if(Input.GetButtonDown(0)){
rigidbody.AddRelativeForce (-1, 0, 0); // 1 Unit left in local axes
}
}


Also it is giving me this error: Assets/TouchControls.js(2,23): BCE0017: The best overload for the method ‘UnityEngine.Input.GetButtonDown(String)’ is not compatible with the argument list ‘(int)’.

I honestly don’t know what I did wrong. Any suggestions would be helpful. Thank You.

  • Tyler Butler

You Get the error because GetButtonDown method does not accept int as an argument, As the error says.

Argument is what you pass into the method. In your case its ‘0’.

Then what should i pass to make this work? Watch this tutorial.

But you said:

I am trying to make touch controls

Try to learn new Unity UI and you are good to go. You can find Tutorials here