Omega2D
1
Hello everyone,
I need your help to know how to make a character selection in my game like the character selection of crossy road game.
My characters will use the same animator controler I only change the sprite and the animation when you change the character.
So please somebody know how to do this in script?
P.S:I using the unity 5.
Thanks for all.
Up to 5.1 you are not able to change animations in an animation controller during runtime. I think I read they might have added this capability in 5.2, but I’m not sure.
Anyway, the alternative, which might even be cleaner, is to use AnimationOverrideController. You can create these objects with right click in your project, and they are simple objects in which you select an original animation controller, and then for each animation of the original controller you provide a different animation (or leave empty to use the original).
This allows you to set an animator controller for selected objects while keeping all the state machine logic of the original controller. The replacement animation will have all the “selected” sprites. Then in runtime, all you have to do is switch one animation controller from the original to the selected version, instead of replacing all the animations from code.
There is a better solution. Use this script - GitHub - RetryEntry/UnityAnimatorChangeSprite: This script will swap sprite of an active animator to another one with the same dimensions.
Please give thumbs up, cause I have spent two days searching through useless solutions like one that soulburner suggected.
If you have 15 gameobjects with 15 sprites in animation chain you will spend up to 225 loops every frame searching for sprites to swap to…
With such approach you CAN’T create for instance charactes with different clothes animated by one animator, cause you will spend 12000 loops every second on useless things like searching. With this script you will not spend time… It uses shaders. You can change it as you’l like, Just star please. I have spent two days… 