- Home /
Simple Animation for Unity3d
Hello Uniters !
I want to ask is there any simple way to just play an animation?
i've watching this Unity3d Video Tutorial about animation.. and it's so great i could really do anything about that.. But, it's too much to do.. i mean, is there any other way to play an animation beside this way? (simpler way)
i've been searching how to play animation, some ppl put out that i should place animation.Play("NameOfAnimation");
on function Update();
but after i attach the script to my character, it wont play that animation at all.. so i really want to know is there any easier way to do this? maybe by only call the name of animation on script, and the object will do it.. or something like that?
i know it's been so may ppl ask about this, but everytime i seach the Answer section, the code just not complete, that my character still not moving..
EDITED and also, when i select my object, there is no "Animation" tab on the Inspector of my object.. why does this happen? and how to make the tab show up on Inspector?
*sorry for bad english.
When you put code in Update(), it gets executed once every frame. Putting your animation in there will make it constantly restart, appearing as if it's not working at all.
Is this animation supposed to be happening all the time, or should it be triggered by a specific event?
it should loop the animation overtime, because it's like walking animation, and i only create 2 step of walking animation..
If it should only happen when you're walking, it would make sense to put it in your movement script. If you don't have an animation component, drag the animation onto the object.
Have a look at the animation portion of the Unity User $$anonymous$$anual, found here.
yeah, i see that $$anonymous$$ecanim work so great for animation on Unity, but if i want to evade that way, is there any easier way? because i don't really understand how to do it...
in $$anonymous$$ecanim it shows, we should import a .fbx file for every movement? isn't that too large?
and how to do it by script? i mean, do i still need to import walk,idle,jump of fbx animation to Unity to able to play the animation by script?
*sorry i know my question is a bit confusing.. i dont know how to tell this on the exact problem i have..
Answer by GameVortex · Jan 14, 2014 at 08:52 AM
The absolutely simplest way I can think of to play an animation would be:
Add your model to the scene as a GameObject.
Add an Animation component to the model.
Add the animation clip you want to play to the Animation components "Animations" list.
Also add the same clip to the "Animation" slot at the top of the Animation component.
Make sure "Play Automatically" is checked.
Press Play.
The animation should now play when you enter play mode.
This is the legacy system so you also have to make sure your model and animation is marked as legacy in the import settings.
wow, thank you very much @GameVortex it's happening ! yeah it could loop now.. but the problem is, how do i play this only when i need it? i mean, the first, object is just idle, but when i press this button, then play this animation? do i need to access the Animation and change the name of Animation?
Now that you know the easy way, you accept the answer, then you're patient and go and learn the right way: http://unity3d.com/learn/tutorials/projects/s$$anonymous$$lth
:D
You do not need to change any name or change the Animation in the top slot. The Animation component has the ability to play any animation in the "Animations" list. So add all animations you want to be able to play on the model to the "Animations" list.
Here is an example script to play animation on a button click.
public class PlayAnimationOnButtonClick : $$anonymous$$onoBehaviour
{
public AnimationClip clip;
private void OnGUI()
{
if(GUILayout.Button("Play"))
{
animation.Play(clip.Name);
}
}
}
Attach this to the same GameObject as the Animation is on. Then add the clip you want to be played to the "Clip" variable of the script. You can easily expand from this.
I would now recommend you to start going through Unity and scripting tutorials to learn Unity properly as @Happy$$anonymous$$oo suggested.
thanks @Happy$$anonymous$$oo and @GameVortex :)
So, i still need to import the .fbx file of every "clip" of animation? because, as far as i know, i still need the fbx to show the movement of any animation.. so do i need to import idle,jump,walk fbx of the object?
There are multiple ways of importing animations. Now would be the time to start going through tutorials and read up on the Unity $$anonymous$$anual. It is all explained there: **AnimationImport**.
Your answer
Follow this Question
Related Questions
How to create a sample Animation Blend test script? 0 Answers
Animation doesn't work 1 Answer
Using animations in prefabs 1 Answer
how to manage fbx files animation (blender) in unity using favascript 0 Answers
How do I animate a 2D sprite? 1 Answer