Hello Im trying to set my game up so that you can slash your sword by pressing a button, I have made an animation for this and written a code but when I press the button the animation won’t play this is my code.
i already set this button up in input what should I do.
I am not totally sure that you can use !"#¤%&/() and so forth using GetButtonDown unless you created them in the input manager. Maybe use GetKeyDown instead. Here is a list of all the keyCodes that Unity offers. http://unity3d.com/support/documentation/ScriptReference/KeyCode.html
can u specificity what you want when u press the button do u want to play animation one time or repeatedly when u press the button .what is happening now using this code
if you try call from inside the gui button loop the call will be a fraction of seconds if you animation to play continuously when gui button is pressed you should call using Boolean function like i have done changes in your coding.
Just to fix your script a little, it wont work if you type if(Input.GetButtonDown(“]”)){ it has to be like this:
function Update()
{
if(Input.GetKeyDown(Keycode.R))
{
//in here you can put whatever you want, for example: renderer.material.color = Color.red for example or as you want animation.play
}
}
This is the first result from a search so I should say that this question and the answers are already outdated. You should use the Animator class instead
For new people who finding this post, here are a simple solution. You could use a trigger, by using this you just need to set the trigger to be used in code:
I am not totally sure that you can use !"#¤%&/() and so forth using GetButtonDown unless you created them in the input manager. Maybe use GetKeyDown instead. Here is a list of all the keyCodes that Unity offers. http://unity3d.com/support/documentation/ScriptReference/KeyCode.html
– LegionIsTakencan u specificity what you want when u press the button do u want to play animation one time or repeatedly when u press the button .what is happening now using this code
– robert_mathewyou can break the Boolean loop or in fbx make animation once instead of loop
– robert_mathew