Whats wrong with this script?

private var dead = false;

function OnControllerColliderHit(hit : ControllerColliderHit) { 
    if(hit.gameObject.tag == "DEATHZONE") 
{ 
        dead = true; 
}
function LateUpdate()
{
    if(dead)
    {
        transform.position = Vector3(0,0,0);
        gameObject.Find("Main Camera").transform.position = Vector3(0,0,0);
        dead = false;
    }
}

I keep getting the error “Assets/Scripts/Death Zone.js(8,10): BCE0044: expecting (, found ‘LateUpdate’.”

You’re missing a closing } on your OnControllerColliderHit method.

If you make sure all your code is properly and consistently paragraphed (which your sample is not) then errors like these should be very, very easy to spot.

Oh I see. Thanks.

I changed the script a bit more and I’m having issues having the “wait” command work

private var dead = false;
private var freeze = false;
static function WaitForSeconds (seconds : float) : WaitForSeconds
{
}
function OnControllerColliderHit(hit : ControllerColliderHit) 
{ 
       if(hit.gameObject.tag == "DEATHZONE") 
        { 
        dead = true; 
        }
}

         function LateUpdate()
{
     if(dead)
     {
		camera.main.transform.Translate(0 , -0.08 , 0);
		yield WaitForSeconds (1);
		gameObject.active = false;
		dead = false;
     }
}

I get the error “Script error: LateUpdate() can not be a coroutine.”

Your lack of indentation makes it more difficult to figure out what’s going on that it needs to be. Maybe it’s not there, or it’s there and you forgot to wrap it in CODE tags like you did the first post? In any event, if you’re too lazy to make your code readable, we may be too lazy to read through it. :wink:

Sorry about that. I’m a complete beginner at programming anything. I’ve never had a class on it or anything. Hmmm, ill try to make it more simple though. Basically what i’m wanting to know is how to make a javascript in unity “Wait” for 1 second.

When I used the method described here http://unity3d.com/support/documentation/ScriptReference/WaitForSeconds.html

I got the error " LateUpdate() can not be a coroutine. "

Update (also LateUpdate) runs every frame without exception, and therefore cannot be made to wait. Just put that code in OnControllerColliderHit; there’s no need for the “dead” variable. (Also you should remove that WaitForSeconds function; it doesn’t do anything and has no purpose since Unity already has such a function built-in.)

–Eric

Thanks! :hushed: Works great now :slight_smile: I really appreciate it.