- Home /
how to make an animation play on input
So I have the fps control (by tornado twins) asset from the store and it comes with all the nescessary animations for an m16 but i don't know how to make the animations play on an input. For example: you make the reload animation play when you press R, fire the gun when you press the left mouse button, or run the sprint animation when you press Shift+w,a,s,d, Thanks in advance.
Reload:
function Update()
{
if(Input.Get$$anonymous$$ey("r"))
{
animation.Play("ANI$$anonymous$$ATON_NA$$anonymous$$E");
}
}
Fire :
function Update()
{
if(Input.Get$$anonymous$$ouseButtonDown(0))
{
animation.Play("ANI$$anonymous$$ATON_NA$$anonymous$$E");
}
}
Run (front):
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
}
Run (back):
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))
animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
}
Run (LeftSide):
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
}
Run (RightSide):
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
}
Answer by Im-Brazilian · Nov 17, 2013 at 05:54 AM
Reload:
function Update()
{
if(Input.GetKey("r"))
{
animation.Play("ANIMATON_NAME");
}
}
Fire :
function Update()
{
if(Input.GetMouseButtonDown(0))
{
animation.Play("ANIMATON_NAME");
}
}
Run (front):
function Update () {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
animation.Play("ANIMATION_NAME");
}
Run (back):
function Update () {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
animation.Play("ANIMATION_NAME");
}
Run (LeftSide):
function Update () {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.A))
animation.Play("ANIMATION_NAME");
}
Run (RightSide):
function Update () {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.D))
animation.Play("ANIMATION_NAME");
}
i just tried the reload script. It didnt seem to work. What i did was i added the animation and script to the fps controller. Do I need to make the animation's name a variable? Thanks in advance.
Answer by DizzyTornado · Nov 17, 2013 at 06:38 AM
Thank you a lot. I'm just wondering what the different mouse buttons are called? I assume mousebutton0=left mouse button and mousebutton1=right mouse button but I'm not sure. Thanks again.
left button mouse : Get$$anonymous$$ouseButton (0)
right button mouse : Get$$anonymous$$ouseButton (1)
middle button mouse : Get$$anonymous$$ouseButton(2)
and if you want to press a key (a,w,p,r,y....) you use Get$$anonymous$$ey("A LETTER")
example:
funtion Update () {
if (Input.Get$$anonymous$$ey("r")) { animation.Play("reload"); } }
haha i'm brazilian i dont know if you really understand alll what i wrotten.
but i read "Thanks a lot" so...You're Welcome
Your answer
![](https://koobas.hobune.stream/wayback/20220613122038im_/https://answers.unity.com/themes/thub/images/avi.jpg)