- Home /
2D-How to call a synced layer animation up in script (Animator)
I have a 2D character with hand-drawn animations. The method that I decided to use to simulate a 'costume change' was to make a new layer in the Animator window and sync it with the original tree. Thus, I can run, jump, and melee attack (to name a few). And no matter what costume the hero wears, he can do all of these things. The animations are essentially what is changing, not puppet parts. Hence the use of Layers. So then, in my MainCharacterMovement script, how can I call a synced layer to replace the original layer? If I have DefaultLayer as the initial layer to start on a new game at runtime, how can I then switch to Layer1 or Layer2? I was thinking my logic would be something like:
if(costume1) switch animator layer
But my problem is that I don't know the syntax to switch layer states, or if it can even be that simple. Also, what dataType are layer states in mecanim? I want to make another variable for writing permanence later, so I want to be able to reference it. Again, I am using 2D everything in this game, collisions, rigidbodies, ect..
Thanks for any help.
I wanted to update my question as I haven't got any responses yet. I am still trying to find the code when I have a layer in $$anonymous$$ecanim that I add in addition to the original layer and use sync on that layer. Example: Layer0 is the base layer which is the default animation. Layer1 is a synced layer. Lets say in Layer0, I want a cube character to be plain blue, but in Layer1, the cube character will have polka dots.... So I have all my animations for this already (in the form of sprites -- from a sprite sheet). In the script,
how can I say:
"Ok, when polkaDots is true, switch to all animations from Layer1? And if polkaDots is not true, switch all animations back to Layer0."
Is anyone able to help?
Your answer
Follow this Question
Related Questions
How to link 2 animations of different objects in Mecanim? 0 Answers
Mecanim Runtime Controller is Private! 4 Answers
How do I make the transition between two states in the "Animator" happen instantly? 3 Answers
Mecanim deltaPosition is increased with more avatars 1 Answer
Animation Speed with Variable? 1 Answer