- Home /
slash sword
I'm making a first person rpg but i want to know how to slash my sword
i tought i could use a script to play my "slash sword" animation but hen i press the button it doesn't do anything
this is my script
pragma strict
function Update () { if ( Input.GetKeyDown("Fire1") ) { animation.Play("slash sword"); } }
Answer by Araph · Jan 22, 2013 at 12:19 AM
To clarify a bit on what Dann said, try something like this:
#pragma strict
public var swordSlash : AnimationClip;
function Update () {
if (Input.GetButtonDown("Fire1")) {
animation.Play(swordSlash);
}
}
Then you can just select an animation clip in the inspector and you're good to go.
One thing, though; I think you meant GetButtonDown instead of GetKeyDown. Are you declaring Fire1 as a button in the Input Manager?
with fire 1 i mean my left mouse button but i've set it in the input settings
the script doesn't work , i've made an animation called swordSlash and i've attached it to my first person controller , then i attached the script to my first person controller and when i want to press play it says :
Assets/scripts/slash sword.js(7,23): BCE0023: No appropriate version of 'UnityEngine.Animation.Play' for the argument list '(UnityEngine.AnimationClip)' was found.
Answer by Dann858 · Jan 21, 2013 at 10:01 PM
You've listed your animation as a variable? I don't recommend using ("...") Instead, just call it a name like: SlashSwordAnim
Your answer
![](https://koobas.hobune.stream/wayback/20220613091338im_/https://answers.unity.com/themes/thub/images/avi.jpg)