- Home /
Script Crashing
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?
Comment
Best Answer
Answer by Eric5h5 · Jun 12, 2011 at 02:56 AM
You don't have a yield in your for loop.
By the way, instead of transform.TransformDirection(Vector3.forward)
, you can just do transform.forward
.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103325im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Code freezes Unity and I don't know how to fix 1 Answer
lerp in coroutine doesn't work correctly 0 Answers
Lerp to target position in X amount of time 2 Answers
Lerping inside Coroutine occurring too quickly 1 Answer
rotate object by list values 0 Answers