Pressed button to play animation?

Hey guys!!
Im new to unity3d engine and im working on a FPS project.
I have my gun model i i’ve animated it to “GunFire”, “GunSprint”, “GunAim”… (Some more)
My question is, how to make the gun that shoot, make damage and play my animations?

For example: My gun deal 30 damage, when i hold “LShift” and run around, it play “GunSprint” animation, and when i press and hold my “RMouse”, it play “GunAim” animation?

Please help :<
Thanks u guys so much
(Im using FPS_Controller prefab from the Default Asset as my player)

2 Answers

2

I’ll try to answer some of it since Im just blankly staring at the screen after just waking up, so add an animation to your prefab as in just add component and type “animation” not animator. Click Animations in the inspector and then see where it says size? Type 1 in the size, then drag your animation into the element 0 AND into the regular animation spot above that, so twice.

Then in code under something like

mouse 0 is left click 1 is right click and 2 is middle mouse button

if (Input.GetMouseButtonDown (1)) {

gameObject.GetComponent<Animation>().Play ("animation exact name");

}

Heyyy, what the different between "GetButton" and "GetButtonDown" @pwego

To play other animation, i just have to write the same as that one right?
I’ve created a new c# script, and, this code is in the Void Start or Update?

Dont hate me because of asking too much, im new :<
@pwego please help

I made some animations, put it in an animator with all the animations. Create "Aim", "Sprint" as Bool and "Fire" and "AimFire" as Trigger How can i put them on the code? plz I've add the animator to my gun. I add "GunNormal" to animation in my gun's animation (cuz i set it as default in my animator). Plz help @pwego :<

Im i right? @pwego <pre> public class AnimationWeapons : MonoBehaviour { // Use this for initialization void Start () { if (Input.GetMouseButtonDown (0)) { gameObject.GetComponent<Animation>().Play ("GunFire"); } } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown (1)) { gameObject.GetComponent<Animation>().Play ("GunAim"); } if (Input.GetMouseButtonDown (0)) { gameObject.GetComponent<Animation>().Play ("GunAimFire"); } } } </pre>

Somewhat, but dont put it in the start method only put it in update. Also you have 2 animations for left click hold. GetMouseButton is pressed once GetMouseButtonDown is it being held down.

Can i do, like.. while you "Aim", you cant "Sprint", just can "AimFire" or "Fire" @pwego

Ohh okayy xD Can i have your email, please. I really need help with this game engine please @pwego