- Home /
How to make animations on button press.
I am trying to make it so my model does animations on a button press. So w for walking and so on. Can someone guide me to make a script for a var as well? So when I edit the character I can select the animation for the button pressed, like the default third person.
Answer by FPSworrior · Jan 17, 2014 at 02:28 AM
//You could put as many of these as you want for more animations
var animationToPlay1 : String;
var keyToPress1 : KeyCode;
var animationToPlay2 : String;
var keyToPress2 : KeyCode;
function Update()
{
if(Input.GetKey(keyToPress1))
{
animation.CrossFade(animationToPlay1);
}
if(Input.GetKey(keyToPress2))
{
animation.CrossFade(animationToPlay2);
}
}
Ok this script looks promising, I'm going to try this when I get home. I tried adding on to it if I need more animations, would this work?
//You could put as many of these as you want for more animations. 1 - Walk 2 - Sprint 3 - Crouch
var animationToPlay1 : String;
var keyToPress1 : $$anonymous$$eyCode;
var animationToPlay2 : String;
var keyToPress2 : $$anonymous$$eyCode;
var animationToPlay3 : String;
var keyToPress3 : $$anonymous$$eyCode;
function Update()
{
if(Input.Get$$anonymous$$ey(keyToPress1))
{
animation.CrossFade(animationToPlay1);
}
if(Input.Get$$anonymous$$ey(keyToPress2))
{
animation.CrossFade(animationToPlay2);
}
if(Input.Get$$anonymous$$ey(keyToPress3))
{
animation.CrossFade(animationToPlay3);
}
}
I get errors for the keys, I put in left shift and other keys like c. Also I cant use it. It says the compilation isnt done
First off, yes you put the script on the player. Also what kind of errors are you getting. Can you put them on here so that I can see them?
Omg nvm, I'm so dumb XD I fixed it you just keep it blank. Going to try the script now. Thanks!
Answer by Prasad uchil · Jan 30, 2014 at 11:31 AM
i have an question how can i put a gui texter or gui button it and this script dosent have any gui option so how can i make it i want to use it in android phone and tab so can you help