Hi I want to click on an object and add force to its rigidbody in a random direction. I’m getting an error message that: Input Button right is not setup. What does that mean?
This is my code
var mag = 2.0;
function Update(){
if(Input.GetButtonDown("right"))
{
force = Random.insideUnitSphere;
getComponent("Rigidbody").AddForce(force * mag);
}
}
You haven’t set up any button called “right” in the input manager.
–Eric
I created a new axis with the input manager.
name -------------- push
Positive Button — right
Type -------------- Key/ Mouse Button
Am I missing anything?
You called your button “push”, but in your script you’re asking for a button called “right”.
–Eric
yeah I tried all the name combos and it still won’t work. I even tried renaming it to “jolt” and GetButtonDown just does not respond. GetKeyDown works with practically identical code :?
Now I am geeting another error:
MissingMethodExeption: Method not found: ‘UnityEngine.Rigidbody.AddForce’.
:shock: :? :shock: :? :shock: :?
It works fine if you use the same name in your code as you have it named in the input manager. If you’re naming it “push” then you need to say Input.GetButtonDown(“push”).
You don’t use quotes in GetComponent, unless you’re trying to specify a script where you don’t know the type, like trying to access a C# script from Javascript. You don’t need to write that out anyway…just do “rigidbody.AddForce(force * mag)”.
–Eric
thanks eric5h5, I’ll give it another try
found the prob. In the input manager - the Alt Positive Button should be set to mouse 0 if you are specifying the left mouse button.