Make player die is they fall for too long

How would I go about achieving this? I'm looking for a way to prevent sequence breaking in my game and am under the impression this would stop that from happening.

If you have a rigidbody on your gameobject you can use the velocity value to determine if your player has died.

http://unity3d.com/support/documentation/ScriptReference/Rigidbody-velocity.html

if(rigidbody.velocity.y > 10){
print("player has died")
}

if you are using a Character controller you might be able to do the same, im not sure though :)

edit:

public float timeinair = 0;
public float deathtimer = 10;
private bool dead = false;

void update(){
     if(!player.isgrounded){
          timeinair += time.deltatime
     }
     if(timeinair >= deathtimer){
          dead = true;
     }
}

Hi,

I would build a simple collider below your platform, and when the player hit that collider, it means death. then you can easily define several similar colliders around your levels at different height.

This would prevent always checking in an update, that's not very efficient.

Bye,

Jean

public float timeinair = 0;
public float deathtimer = 10;
private bool dead = false;

void update(){
if(!player.isgrounded){
timeinair += time.deltatime
}
if(timeinair >= deathtimer){
dead = true;
}
}

Blockquote

The above code posted by @Kacer is great, BUT it has one critical flaw. You need to add a condition
to check for the controller being grounded, too. Otherwise the timeInAir will just continue to accumulate. (If you’re a newbie, you can watch this happening in the Inspector as you play). For example, if a player merely jumps a few times, the death condition will be satisfied. Not cool, especially if your game has any platforming.

Here’s my variation of the code in C#:

using UnityEngine;
using System.Collections;

public class DeathCheck : MonoBehaviour
{

public float timeInAir = 0f;
public float deathTimer = 3f;

private bool deadGirl = false;


// Update is called once per frame
void Update () 
{
	ShesDeadJim ();
}

void ShesDeadJim()
{
	CharacterController controller = GetComponent<CharacterController> ();
	if (controller.isGrounded) 
	{
		timeInAir = 0f;
	}

	if (!controller.isGrounded) 
	{
		timeInAir += Time.deltaTime;

	}
	if (timeInAir >= deathTimer) 
	{
		deadGirl = true;
		print ("She's dead, Jim!");

	}
}

}

For newbies, I’ve created a function and called it from the Update function instead of putting the whole thing in Update.(Better practice for lots of practical reasons). Also, the deadGirl variable is unnecessary and redundant unless you’re going to use it for specific purposes, and it might cause a warning to appear in the console.

well you could make it so that if your player falls to a certain point, then you basically respawn it to another.... Here is a script that i use:

function Update ()
{
    //check if you character fell off the platform
    if(transform.position.y < -10)
    {
        transform.position.y = 5.329594; //set the y axis that the player will spawn to
        transform.position.x = 5.203072; // set the x axis that the player will spawn to
        transform.position.z = -46.88659; // set the z axis that the player will spawn to
    }
}

where it says "`< -10`" it means that when the player is below that in the y axis, then it will respawn the player to where ever the next three transform.position axis are located.

attach this script to your player game object...

hope this helps

-Grady

(script from tornado twins)