what's the best way to change animators on a player, in script?
In my test scene I have a character who I want to switch animator controllers whenever I press a button. For example from rifle to handgun. What's the easiest and least performance hitting way to do this?
Thanks.
Answer by DiegoSLTS · Aug 31, 2015 at 08:36 PM
Get the animator component on the object and a reference to the animators you plan to use, and change the current animator controller using the runtimeAnimatorController property: http://docs.unity3d.com/ScriptReference/Animator-runtimeAnimatorController.html
Also, "least performance hitting"? How many times per second will you switch the animator controller? Hits in performance come from things you do really often or things that needs a lot of processing. I'm not even sure if there are other ways to change the animator controller (it's the only public property to access it), but if there are, you shouldn't worry a lot on the performance of the methods.
thanks a ton, they will switch the animator a lot (sometimes every second) but usually only when a clip runs dry.