- Home /
Open/close door, lags if I walk into it.
If I make a door open and close, with this script. It opens and close fine, but if I walk into the door, it will lag insanely, until I get away from the door. When away from the door, everything is fine.
Any ideas?
var IsOpen : boolean = false;
var CanOpen : boolean = false;
var Volume : float = 0.5;
function Start () {
audio.volume = Volume;
}
function Update () {
if(Input.GetKeyUp(KeyCode.E) && !IsOpen && CanOpen)
{
Opening();
IsOpen = true;
audio.Play();
}
else if(Input.GetKeyUp(KeyCode.E) && IsOpen && CanOpen)
{
Closing();
IsOpen = false;
}
}
function Opening()
{
for (var i = 0; i < 100; i++)
{
transform.Rotate(0,0.9,0);
yield WaitForSeconds(0.01);
}
}
function Closing()
{
for (var i = 0; i < 100; i++)
{
transform.Rotate(0,-0.9,0);
yield WaitForSeconds(0.01);
}
}
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.tag == "Player")
{
CanOpen = true;
}
}
function OnTriggerExit (other : Collider)
{
if(other.gameObject.tag == "Player")
{
CanOpen = false;
}
}
@script RequireComponent(AudioSource)
Comment