- Home /
Animation Script
Hi all! I got this script off of Unity's scripting reference. I need to modify it to play my several animations.
function Update () {
if (Input.GetButtonDown("Fire1"))
animation.PlayQueued("shoot", QueueMode.PlayNow);
}
Instead of "shoot" I want it to play my animations. So how do I list the names of all my animations in there? Thanks!
Answer by Fragmental · May 08, 2014 at 04:30 AM
One way to do this is with mecanim https://www.youtube.com/watch?v=Xx21y9eJq1U ,which might be your best bet, but a simple script like above does seem much easier.
Edit: I experimented some more and I got this to work. I had to restart Unity because it froze about a half dozen times in the process. Not sure why. I think it happened when I was saving the import settings.
When you import a file with your animations, you can find those animations in the inspector in the import settings when you select your imported asset in the projects window. You can then rename the clip or create new clips if you have multiple animations, in the same file. You can then select those clips and drag them where you need them from the project window after you expand your imported asset. Or sometimes you can find them in a list of assets when you click the options next to a parameter that takes an animation.
This is true for mecanim and the method you mentioned above. I believe that mecanim is the new way and the way you mentioned is the old way.
In order to use the old way, you must first set the animation type to "legacy" in the "rig" tab of your import settings. Then you follow what I just describe regarding creating your clips. Then you add the "animation" component, which can be found in "miscellaneous", to your object in the hierarchy of your scene. Then you can add an animation to "animation" which is the default or idle animation. Under "animations", you set the "size" to the number of animations you want to use with that object. Uncheck "play automatically"(unless you need your idle animation to automatically play). You should then be able to add the name of the animation you added to "elements" as a string in your script.