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.
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.