Playing animation with keyboard lock

Hello, hopefully wont be a silly question.

Currently been using unity for a couple of months and love it. I’m very much self taught due to being an animation student. So i have quite a few gaps in my knowledge. Normaly i try and work it out myself but hit abit of a sticky wicket.

I’m looking to have an animation play in the background which i wish the user to watch and lock key strokes for a set amount of time.
I’ve got the animation playing and the level change works fine but has hit this problem.

Animation plays ->keyboard locked set amount of time->User presses E->level change.

Now i have looked at boolean’s with not alot of luck as some other people have this issue.

Hopefully someone with more knowledge can point me in the right direction. Thank you in advance.

You already have the boolean checking if you can or cannot detect inputs apparently, and the animation is played correctly. Then, the issue is to wait for the end of the animation before allowing inputs.

The simplest way will be to use Invoke. Create a simple function that only set your boolean to true, such as

function EnableKeyboard()
    enableKeyboard = true; // or whatever names you want

then, when you start the animation, call Invoke( “EnableKeyboard”, 15 );. You could also use the length of the animation with animation[ ].length.

Now, if you want to understand coroutines. yield is going to pause the function for some time according to what you return.

yield null will wait until the next frame. yield WaitForSeconds(10) will wait 10 seconds, which means your timer in your comment won’t do anything. Try that script

function Start()

function CoroutineWithNull()
    print( "CoroutineWithNull start" );
    var timer : float = 0;
    while( timer < 5 )
        yield null;
        timer += Time.deltaTime;
        print( "CoroutineWithNull " + timer );
    print( "CoroutineWithNull done" );

function CoroutineWithWait()
    print( "CoroutineWithWait start" );
    yield WaitForSeconds( 6 );
    print( "CoroutineWithWait done" );