Page 1 of 1

Animations

Posted: Sat Mar 10, 2018 4:38 pm
by Capstone56
Hello,

I am creating a game that requires different animations to be triggered depending on the dialog that the user selects. I have tried different ways to do this with no success. I tried to use the Sequencer field, using Animation(), but for some reason it does not work but works when trying to implement Audio files in the Sequence. I tried following the documentation but it still did not work on my game. What is the easiest/best way to implement different animations, dependent on what dialog option the user selects? (the more detailed explanation the better!)

Re: Animations

Posted: Sat Mar 10, 2018 5:24 pm
by Tony Li
Hi,

The Sequence field is definitely what you want to use. It depends on which animation system you're using.

The Animation() sequencer command is for the legacy animation system -- that is, if your GameObject uses the legacy Animation component.

If you're using the Mecanim animation system -- that is, your GameObject has an Animator component, use the AnimatorXXX() sequencer commands, such as AnimatorPlay(). You should be at least a little bit familiar with how Unity's Animator works. These tutorials are helpful. These are the AnimatorXXX() commands:
  • AnimatorPlay(): Plays or crossfades to an animator state.
  • AnimatorWait(): Plays or crossfades to an animator state and waits until the state is done playing.
  • AnimatorBool(): Sets an animator's bool parameter.
  • AnimatorFloat(): Sets an animator's float parameter.
  • AnimatorInt(): Sets an animator's int parameter.
  • AnimatorTrigger(): Sets an animator's trigger parameter.
  • AnimatorLayer(): Sets the weight of an animator layer.
  • AnimatorController(): Swaps the animator controller asset used by the animator.

Let's say the conversation looks like this:
  • NPC Teacher: "Who wants to solve this problem on the blackboard?"
    • Player: "Choose me!"
    • Player: <slump down to avoid notice>
    • Player: "Too easy! I'll wait until you have a harder problem."

Assume that the player has an Animator with states named "RaiseHand", "Slump", and "Yawn". You could set the Sequence fields to:

Let's say the conversation looks like this:
  • NPC Teacher: "Who wants to solve this problem on the blackboard?"
    • Player: "Choose me!"
      Sequence: AnimatorPlayWait(RaiseHand)
    • Player: <slump down to avoid notice>
      Sequence: AnimatorPlayWait(Slump)
    • Player: "Too easy! I'll wait until you have a harder problem."
      Sequence: AnimatorPlayWait(Yawn)