Hi, I have a character and all of his Animations are operated using animation controller. I want to write a script that will simulate this. I simply want to minimize the dependency on the Unity UI. I guess I need to use some sort of an animation clips array for the changes and time it out somehow. Did you ever do something simlliar ? What does this involve? Thanks !
Animator controllers handle the animations in unity. The only way I know of to access an animation via script would be through an animator. Drag all the clips into an animator, then create an animator in your script
public Animator anims;
public Animator anims;
//bla bla
if (getKey(Keycode.W))
{
anims.play("WalkForward");
}
if (getKey(Keycode.W))
{
anims.play("WalkBackward");
}
and so on. This wouldn’t work tremendously well unless you made manual transitions for every animation. This is kind of the main advantage of unity’s animation controllers, they have nice transitions that don’t break that often.
For a transition, you could check for the key up, Check instantly for another key down, if that combo has a possible transition, play it then play the next animation. I’m not sure why you want this independence from unity’s UI. You are still using the unity system just in a less stable C# environment. If I’ve misread your question, let me know.
Thanks for you commment. Let me explain furthermore what I am wishing to do.
I have a character that has a lot of idels animations and a lot of talking animations.
I wish to have a script that just changes idle animations randomly at the background.
Whenever i do a operation (lets say press a key word) it will change to talking animation in random.
I am thinking about creating 2 arrayies. one for talking animations and one for idle and change between these using a script and not the animator. Is it possible ?
Thanks
I would recommend putting all your animations into an AnimationController and using StateMachineBehaviors to accomplish what you what. David Geoffrey covers this for melee animation in this video:
The same technique could be applied to your case.
If you really want to go the route of not having to work directly with the AnimatorController Editor in Unity, then you could write your own animation system using the Playable API which Mecanim is built on top of. The Playable API is in the Experimental namespace in 5.x releases, but will be moved out of experimental for 2017.1 if I’m not mistaken.
Cheers,
TrickyHandz