Hi, I'm pretty new to Unity and Java script and I'm current creating an FPS. When I press 1 to pull out a weapon a animation is automatically played but if I shoot during the animation then the gun freezes halfway and plays the shooting animation. I want to be able to shoot while the gun is still being pulled out without it stopping the animation. Here is the code I am using Code (csharp): //attach this script to the object you want the animations to play on when //clicking the Left mouse button. //Remember the name of your animations! function Update () { if (Input.GetButtonDown("Fire1")) //check to see if the left mouse was pushed. { animation.Play("Glock_Shoot"); // if pushed play the animation listed within the quotation marks. } //add multiple animations by copying and pasting this code (below for else if) and changing //the animation and button. } The animation that is played automatically using the Inspector is called "Glock_Start" Also I have tried using animation.CrossFade but this makes the shooting animations buggy and unresponsive
So basically what you're saying is you want the "Glock_Shoot" animation to play when you fire, but if the "Glock_Start" animation is still playing from when the player chose this weapon, you still want to be able to shoot but you don't want it to play the "Glock_Shoot" animation? You could just do: Code (csharp): if (Input.GetButtonDown("Fire1")){ if(!animation.IsPlaying("Glock_Start")){ //if the glock start animation is not playing animation.Play("Glock_Shoot"); //play glock shoot } }
Great thanks, this worked just great Sadly I've encountered another problem, When I press the W key to move forward I want to play the animation "Glock_Walk", this works except once the animation stops its doesn't start again, I've tried using "animation.wrapMode = WrapMode.Loop;" but that just made all the animations look, also if I spam the W key the animation keeps jumping straight back to the start instead of continuing and only starting agian if it has stopped. Here is the code I'm using: Code (csharp): function Update () { if (Input.GetButton("Vertical")) //check to see if the left mouse was pushed. { animation.Blend("Glock_Walk"); // if pushed play the animation listed within the quotation marks. } if (Input.GetButtonUp("Vertical")) //check to see if the left mouse was pushed. { animation.Stop("Glock_Walk"); // if pushed play the animation listed within the quotation marks. } }
so your problem got answered, you ran into another one and immediatly came here for help instead of spending a few hours trying to fix it yourself? no wonder you haven't been active in almost 10 years.
When you're angry because you can't find a solution to your problem and you take it out on this guy. wtf.