Using Animator.SetTrigger(string)

You can use the Animator.SetTrigger method to activate a trigger, which can then cause a transition to occur. The transition will take place as you have defined it and may not be instantaneous. However, this enables you to create more realistic transitions between animations. For more information, see Defining Animator transitions.

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.

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.

Last updated