Question by
ouchyzapgun · Dec 28, 2015 at 01:48 AM ·
scripting problemrigidbody
What's the Problem with This Movement Script?
I tried creating a simple horizontal movement script. I get no errors. But when I run the game, the object does not move when I enter inputs. Here is the JavaScript script in quot marks. Sorry that it looks messy here.
"#pragma strict
public var paddleSpeed: int = 100;
function Update () { if (Input.GetButton("Horizontal")) { GetComponent.().AddForce(paddleSpeed, 0, 0); } } " What is wrong? The object has a Rigidbody already, by the way.
Comment
Answer by mikelortega · Dec 28, 2015 at 12:53 PM
"Horizontal" is not a button, do you mean Input.GetAxis? Also, GetComponent needs the type, like GetComponent.<Rigidbody>()
or GetComponent(Rigidbody)
Your code would look like this:
function Update ()
{
if (Input.GetAxis("Horizontal"))
GetComponent(Rigidbody).AddForce(paddleSpeed, 0, 0);
}