- Home /
How can i make it so animation would play only when button is being pressed?
Hello ive been having problems for over 4 months for just one thing how can i make my gun play a sprinting animation when the key is being pressed? i have the animations ready for the gun itself.i need it to play the sprinting animation which is called "RunMk11" when leftshift is being pressed. It will really be a big help to me if someone awnsered! thanks! Kind regards to all!.
var Run$$anonymous$$$$anonymous$$11 : Animation;
function Update()
{
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift))
{
Run$$anonymous$$k$$anonymous$$11.Play();
}
}
in order or this to work you would have to attach this script to your player, select the script and in the inspector look in the script component for the prompt "Run$$anonymous$$$$anonymous$$11". Then drag your animation onto that spot. Now when you press left shift it will play that animation.
Thanks for awnsring! and i tried to drag the animation to it but it wont go in to it it keeps saying none(animation) it dosent allow me to drag an animation to it.
Ah yeah I think I know the problem. Go to your player and do
Add Component --> $$anonymous$$isc. --> Animation
Animation!! not animator. Then drag your $$anonymous$$$$anonymous$$11 into the animation component. Then drag your animation component into the animation spot on the script.
Still not working huh add me on Skype:hamadqtr12 This is a serious problem if you can help me fix this mark my words i will give you 50$
OP said 'while leftshift is being pressed' so the Get$$anonymous$$eyDown should be Get$$anonymous$$ey
Your answer
![](https://koobas.hobune.stream/wayback/20220613141504im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Instantiating Multiple Clients into one 2 Answers
i want to make an android app but can't set the bundle indetifier 0 Answers