var HaloLight : Light;
private var HasStarted : boolean = false;
function Update () {
var info : RaycastHit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), info, 0.18)) {
if (info.transform.gameObject.tag == "Tire") {//Tire is in position
info.transform.rigidbody.velocity /= 1.5;//Slow tire down
if (HasStarted == false) {//Have we done this before?
StartCoroutine(Teleport(info.transform.gameObject));
HasStarted = true;
}
}
}
}
function Teleport (Tire : GameObject) {
for (i = 0; i<1; i+=Time.deltaTime) { //The light grows...
HaloLight.range = Mathf.Lerp(0,4,i);
}
Tire.SetActiveRecursively(false);//Hide tire
yield WaitForSeconds(0.5);
Camera.main.SendMessage("fadeOut");
}
This is attached to a “teleporter”. When the tire hits it, the light should grow until the tire dissapears and the screen fades to black. However, when StartCoroutine is called, Unity freezes and I have to force quit. What’s wrong?