Turn off interaction while certain animations are playing

I'd like to create animations, where the user should only be able to provide gui input at specific times in the animation. He should however not be able to move or rotate freely within the scene, i.e. no cursor or mouse navigation.

What's necessary to do that?

Thanks, flexrails

In the script that takes care of the cursor or mouse navigation, you can make a conditional, like this:

var allowNavigation : bool = true;

if (allowNavigation == true) {
    ... your cursor or mouse navigation code here ...

You can then switch that variable, allowNavigation, off and on based on timing in the animation. A few ways to do that:

  • In Update(), check if the time of the animation state is within certain values, like this:

    var animTime = animation["myClip"].time;
    if (animTime > turnOffTime && animTime < turnOnTime) {
        allowNavigation = false;
    else {
        allowNavigation = true;
  • Use the Animation View to add AnimationEvents in the animation clip which call a function that can turn allowNavigation on and off.*

  • Use the Animation View to animate the allowNavigation variable directly. A value of 0 mean false and 1 means true. You can use stepped interpolation.*

*** These solutions doesn't work on imported animation clips, since they are read-only. However, they work on animations created directly with the Animation View, or on duplicates of imported animations.