Enabling control after some time

Hey. Basically what I want is when the player enters a trigger, an animation plays. I got that all right:

var object : GameObject; //treasure chest prefab goes here
 
function OnTriggerEnter (col : Collider) {
 
if(col.gameObject.tag == "Player") { //checks to see that our character controller with tag "Player" has entered the trigger
object.animation.Play(); //plays the default animation applied to our treasureChest model
Destroy(gameObject);// destroys the gameobject that has this script, so our collider in this case
 
}
}

But then, I want to disable player’s movement for some time (1.517 is the animation’s lenght). So here’s my current script:

function OnTriggerEnter(other : Collider){
   if(other.gameObject.CompareTag("Player")){
      var charMotor : CharacterMotor ;
      charMotor = other.GetComponent(CharacterMotor) ;
      charMotor.enabled = false ;
      yield WaitForSeconds (1);
      charMotor = other.GetComponent(CharacterMotor) ;
      charMotor.enabled = true ;
   }
}

Thats not mine. It disables, so just that you can’t walk, you can still move the camera. What I want to happen is so that after entering the trigger you can’t move and you can’t move the camera until the animation ends. (Thanks for this script to Unity community!) I edited the last part only, but for some reason it doesn’t work. I want for it to be able to move again. Thanks. I hope you can understand what I’m writing here. :wink:

EDIT: I managed to get the player back to control by removing the Destroy line. So what I need now, is to modify the script, so that it doesn’t let mouse move, and it returs to normal after some time.

One way to do that is to create a variable whoch you set to false and after to ture. Then reference in every Script which manages Player Movement/Camera and only let action happen if the variable is true.

The cooler way:
Is to create one Script and reference all other Scripts in the first. Deactive and activate them with your main Script. Here’s an example how this Script could look like:

using UnityEngine;
using System.Collections;

public class Activator : MonoBehaviour {
		
	//This Script deactivates all not needed Scripts on a Player
	public Behaviour[] Scripts;

	void OnTriggerEnter(Collider other)
	{
        if(other.gameObject.CompareTag("Player")){       
		//deactivate the Player Scripts

		      for (int i = 0; i <= Scripts.Length-1; i++)
	          {
		            Scripts*.enabled = false;*
  •             }*
    
  •  }*
    
  • }*
    }
    But remember to drag all Scripts into the array in the Inspector. Also add a function to reactivate the Scripts. Sorry that this is a C# Script, I use this function in our project. I think you should get the Idea of it and can convert this to javascript.