The effect

implementation

1. Create animation

2. Drag the image into the animation

3. The effect and duration of sequence frame animation can be controlled in the animation

4. Add the Animator component and set the state machine.

Create an empty node in the state machine and set set as Layer default state, so that the state is initially executed to the empty state, and then attach the created ainmation01 to the empty node. Note the direction, so that after playing the animation01 code, The state will go back to empty again.

5, code control, because the script is directly hanging on the button, you can directly get play.

public class test02 : MonoBehaviour
{
    public Button btn;
    void play()
    {
        this.GetComponent<Animator>().Play("btn01"); }}Copy the code