Here we have a newly created earthquake animation based on subject matter expert input.
When setting the Shape Keys up in Blender
I referred -- in part -- to this graphic,
presented by Dr. Thomas Heaton, from the California Institute of Technology in his talk,
The Physics of Tall Building Collapse, available on Youtube.
Link in the Description below.  https://youtu.be/nknGibToARc?t=2735
We have one tower on the left, that will have
damping applied, and one on the right that
does not.
So we needed two separate controls for when
the building is properly dampened, versus
when it is at risk of collapse.
The first step to triggering these animations
via a button, is to add a blank animation
that we can record to.
So I create one in the Project window, and
name it something obvious like Quake.
Then I need a Controller for my Animator component,
so I go ahead and create that in my project
as well.
With that selected, in the Animator window,
I drag and drop my Quake Animation.
I'll go back to that in a moment.
First, I have to select my tower and drag
that Animator Controller into the Animator
component of my mesh.
Now with that Animation on the tower, I can
click Record and start setting some key frames.
I'll just set them on zero to start with,
and then space them out a bit.
I'm not showing the full extent of how these
animations will play, just the concept of
how you trigger one with a button.
But I am
going to show you how to loop it.
Set the last keyframe to match the first.
Stop recording.
Now when you press Play, it sort of loops.
You'll still need to go into the inspector
window and select Loop Time on the Animation
itself, for it to loop in Play mode.
That's almost done, but we can also make it
loop smoother.
I reset the animation to the start, and select
all of the keys.
Then, I had to do a little testing to remember
the correct setting,
but what I want is the
Auto option enabled.
That smooths out the curve ends so that it bounces back and forth without the hiccup.
You can adjust that further, but what I want
to show next is how to wire this up to a button.
So we go into the Animator window again,
and
add a new Parameter.
Choose the Trigger option, and then I'm gonna
name it Quake as well.
The default Entry Transition isn't available
to be selected, so what I did first is Right
Click the Entry and choose Make Transition.
That makes a new arrow between the two that
I can select,
and then I can set my new Quake
Parameter Trigger as the Condition for the
Transition.
Then I went into my Canvas, where I've already
set up a default Button.
The Button component has an On Click event
field, so you just drag your animated object
into the slot in the On Click Event,
choose
the Function,
for this it's the Animator,
and Set Trigger, type String.
Then in the String field, you write the name
that you gave the Parameter that you want
triggered when you click the Button.
When I push play here, I realize that this
isn't quite right.
I need the animation NOT to run automatically
in Play mode.
So what I need to do is create an Empty state,
where the Animation isn't playing,
and then set the Entry Transition to that Empty.
I get confused by the wires crossing, so I
just deleted the Quake Animation for a second,
make sure that the entry is into the Empty
state,
and then I drag and drop the Quake Animation back in.
And that's where I'll set my Parameter as
the Condition for the Transition.
Everything looks right, so I test it out,
but something's still wrong.
Turns out, at some point I had accidentally
disabled the EventSystem for the Canvas in
the Inspector window, so
when I turn it back
on,
everything is working as expected!
