- Home /
Very silly and simple javascript question
I want a gun to be able to shoot while on the hip, shoot while aimed, aim in and aim out. I got the parts working where it zooms in, zooms out, and shoots in the hip, but the last part i just can't get. Look at the last if statement and i need to know what i did wrong' #pragma strict var aim = true;
function Update (){
if(Input.GetKeyDown(KeyCode.Mouse0)){
animation.Play("1911shoot");
}
if(Input.GetKeyDown(KeyCode.Mouse1)){
animation.Play("1911aim");
aim = false;
}
if(Input.GetKeyUp(KeyCode.Mouse1)){
animation.Play("1911unaim");
aim = false;
}
if(aim == true && Input.GetKeyDown(KeyCode.Mouse0)){
animation.Play("1911aimShoot");
}
}
Where are you setting aim to true? EDIT: Sorry, I see it is declared as true.
Answer by POLYGAMe · Feb 16, 2014 at 10:42 PM
You've got it running two IF statements at a time... the first one and the last one, and the two in the middle. So if you press mouse 1, it will run both of those missile Ifs, as you haven't specified a condition in which to run it. I'm not too familiar with animations but it looks to me like it will start one animation, then instantly start the next,
Try setting up extra bools like "isAnimating" and wait for that to finish etc.
EDIT: I just notice that one of them is GetKeyUp, so ignore the bit about the two middle IF statements. It will still try and run both the first and last ones though, if the aim boolean is true.
Without knowing exactly what you are trying to do, maybe try:
if(Input.GetKeyDown(KeyCode.Mouse0))
{
if(aim)
{
animation.Play("1911aimShoot");
}
else
{
animation.Play("1911Shoot");
}
}
Thanks so much, ive only written a total of 5 scripts without tutorials that actually works so yeah im a noob but i really appreciate your help
No worries, I was in the same situation a few years ago. I can make games now :D I'm still not a great coder but hey, I manage to get it done. LOL. Good luck!
Oh, please accept the answer if this helped. Feel free to vote up, too ;)
Your answer
Follow this Question
Related Questions
Which code do I use to change animation of Spine? (Noob..) 1 Answer
Animation doesn't work 1 Answer
Using animations in prefabs 1 Answer
new Vector 3 help 1 Answer
how to manage fbx files animation (blender) in unity using favascript 0 Answers