Using Animator.Play(string)
Last updated
Last updated
You can use the Animator.Play
method to play a specific animation clip. When you call the Play
method, the animation clip begins to play immediately. If a different animation clip is playing when you call the Play
method, the playing clip is interrupted.
The example on this page uses the version of the Play method that takes a string parameter - which is the name of the animation clip that you want to play. There is also a version that takes an integer parameter - which is the index of the animation clip that you want to play.
This example is like the Network state animation start/stopexample, in that is uses a combination of a NetworkStateTrigger_ToggleObjects
script to coordinate the network state, and an OnEnableDoEvent
script to call the desired methods.
However, this example uses two buttons, which specifically set the state to 1 or 0, instead of a single button that toggles between the two states. Both methods are interchangeable and you can pick whichever matches your needs.
The following diagram shows an example of how to arrange the components in Unity, and the required references.