My last Unity3D example showed how to interact with a standard Blender model. The TV model in that example had no animations just a separate dial object that I manually rotated in Unity. In this example I wanted to trigger a Blender animation when an object was clicked.
My brother Calin was nice enough to create the required Blender models for me and animated them using an Armature. For these models he set each animation to 25 frames in length (length of the animation is important to know as it will need to be entered into Unity).
After importing each model into Unity each animation’s name, frame start and frame end will need to be entered.
Ex: open 0-25, close 26-50
Once a model is added to a GameObject the animation component can be setup. In this example the default animation was set to none and ‘Play Automatically’ was disabled. This way no animation would be played at start up. Each previously entered animation can then be added to the animation list.
Once complete the default collider(s) can be added to the GameObject. Also if needed colliders that will need to follow the animation’s motion can be added to that joint GameObject. (ex: fridge door joint). This way during and after the animation all colliders will be in the correct location.
Finally from within the GameObject containing the model with an animation you can call ‘this.transform.animation.Play(“animationName”);’ to trigger that animation.
While setting up each animation and all the colliders can be a little time consuming once you get the hang of it, it becomes pretty easy.
Thanks again to Calin for creating these models.
To check out the demo click here.
To get the source (unitypackage) click here.
Source Requirements: Unity 2.6, you will only need Unity Pro to use the Render Texture feature used for the TV.
Update: The original version of the unitypackage was missing the scene file. This has now been corrected.