Game Development Reference
In-Depth Information
Figure 10-26. The animation states in the Animator view
To prevent it from playing automatically on start up, you will script it to start at the end of its
animation clip, where it immediately goes into a “holding pattern.”
To trigger the animation, you will create a small script and a few of the functions that check for
mouse activity.
1.
Create a new C# Script in the Menu Scripts folder, and name it MouseOver .
2.
Add the following variables:
Animator animator; // the component
public string clip1;
public string clip2;
Identify the Animator component in the Start function:
3.
animator = GetComponent <Animator>();
Also in the Start function, below the line that finds and assigns the animator ,
tell the clip2 to start playing at the end, 1 or 100%, of its animation:
4.
animator.Play (clip2,0,1f); // start the state in layer 0 at the end of its animation
5.
Add the following three functions:
void OnMouseDown () {
print("ouch!");
}
void OnMouseEnter () {
animator.Play (clip1);
}
void OnMouseExit () {
animator.Play (clip2);
}
 
Search WWH ::




Custom Search