Am currently animating some of my gameobjects by creating an animation controller and animation clips specific for that gameobject. All of the animations clips contain a start animation. Currently I have to create separate animation clips, like gameobject_Start and gameobject_Stop. I would like to reuse the same script and just call gameobject.GetComponent().play(“Start”) instead of passing in manually gameobject_Start.
The example I’m trying to duplicate is the UI Button animation transitions. When you change the Transition type to animation and auto generate, it creates an animation controller and sub animation clips. How can I “marry” the Start and Stop animations to a parent animation controller?
Thank you superpig for the link. I was not able to figure out how to get it to add an animationclip to an animator that I had already set up in my project. I tried creating a new animator and animationclip like in the example, but always got a null reference exception when trying to add the clip to the animator. Below is the code I can’t get to work. I’m assuming it’s because I have not specified any values for the Animator/AnimationClip.
You need to associate the Animator with an asset before you can then add other objects to it - use AssetDatabase.CreateAsset with your ‘anim’ first, then AddObjectToAsset with ‘clip’ after that.
I tried to create the asset first and still got a null reference exception. I couldn’t find a constructor listed for the Animator, so I have no clue what arguments I can/need to pass to it.