i am using this script to rotate the barels on my minigun that i made with unity but it does not work. what is missing or wrong with this script.
//Rotate when spacebar is down.
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function Update ()
{
if(Input.GetButton("Rotate"))
{
gameObject.Find("Tumbler");
}
}
You haven't added any code to do the rotation. If you don't tell it to do anything, nothing will happen.
Well, for one, your if-clause is invalid. You test Input.GetButtonDown but provide no code to run a successful check. It seems to me you're a bit too fresh on coding (apologies if you overlooked this yourself). Maybe you should get more acquainted with JS before you go on.
Anyhow, given you have a function called "Something", this should solve that part
function Update ()
{
if (Input.GetButtonDown("Rotate"))
{
Something();
}
}
Well, presuming you actually assigned the space bar to the button name 'rotate'... I would say the problem is your script doesn't do anything. In the update function you just have 'if this button is held down' and nothing else. That if statement will never work because you're not telling it to do anything if its down. Also, GetButtonDown only does it when you press the button, not if you're holding it down, so it will only do whatever you want it to do once, even if you did have code there.