How would I make a death on touch effect aka death zone

Hello,

I am trying to create a box (death pool) to kill my character as soon as he lands on it instand death, as soon as he lands on it then fades to red, respawns and loses a life, whilst making a sound, so far I have this, which works, the player dies but I don't know how do the rest.

var deathSound : AudioClip;

function OnTriggerEnter (other : Collider) {

    //LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.red, 1.0);

// destroy all game objects that enter this area
  Destroy(other.gameObject);
    audio.PlayOneShot(deathSound);

}

P.S I have also noticed the sound starts when I play the game but at a higher picth, I have noticed this on a few things, the audio source isnt on play on awake either

[EDIT]

The above code can make my character dissapear on collision, however I want it to loose a life fade red and respawn, here is my scripts for the robot controls death part and the health scipt:--

    function Spawn () {
    // reset the character's speed
    movement.verticalSpeed = 0.0;
    movement.speed = 0.0;

    // reset the character's position to the spawnPoint
    transform.position = spawnPoint.position;

}

function OnDeath () {

    Spawn ();
}

and here is the health

 function ApplyDamage (damage : float) {
    if (hitPoints < 0.0)
        return;

    // Apply damage
    hitPoints -= damage;

    // Are we dead?
    if (hitPoints < 0.0)
//audio.Play();
        Die();
        //add a hit sound here
    audio.PlayOneShot(hitmetal);
    //audio.clip = hitmetal[Random.Range(0, hitmetal.length)];
    }

function Die () {

    // Disable all script behaviours (Essentially deactivating player control)
    var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
    for (var b in coms) 
        var p : MonoBehaviour = b as MonoBehaviour;
        if (p)
            p.enabled = false;
    //subtract life here
    PlayerLives.LIVES -=1;

    audio.PlayOneShot(deathSound);

//fades screen to red when dead

    LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.red, 1.0);

    //explodes characters
    var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
    Destroy(gameObject);
}

So im really after what piece of code would I put in this new death pool script inbetween what I already have

Make sure your "death pool" object has a collider attached, then place a script like this on it:

function OnCollisionEnter( collision : Collision ) {
    if ( collision.gameObject.tag == "Player" ) {
        var player : Player = collision.gameObject.GetComponent(Player);
        player.Kill();
    }
}

This script assumes your character is tagged "Player, and has a script called "Player" attached, with a function inside called "Kill".

For fading to red, I used a script in a recent project which drew a small 16x16 pixel texture over the whole screen and changed it's alpha over time to fade it in. In either your collision detection script or your player script, you would place the following function:

var fadeTexture : Texture2D;
private var StartTime : float;
private var StartFade : boolean = false;

function OnGUI(){
    if(StartFade){
        GUI.color = Color.black;
        GUI.color.a = Mathf.Lerp(1.0,0.0,(Time.time-StartTime));
        GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), fadeTexture);
    }
}

The fadeTexture is the texture to use to cover your screen (a small red texture in your case) which you assign in the Inspector.

The line

GUI.color.a = Mathf.Lerp(0.0,1.0,(Time.time-StartTime));

fades in the texture by interpolating it's alpha value from 0.0 (invisible) to 1.0 (fully opaque). Swap the numbers round for a fade out.

When your player touches the trigger, set StartFade to true and store the current time, then call the above function from within your collision code to start the fade:

function OnCollisionEnter( collision : Collision ) {
    if ( collision.gameObject.tag == "Player" ) {
        var player : Player = collision.gameObject.GetComponent(Player);

        StartTime = Time.time;
        StartFade = true;
        player.Kill();
    }
}

It sounded like you weren't sure how to respawn the player and deduct health, so for that you could have something like the following in your kill() function:

var respawnPoint : Transform;
var playerHealth : int = 10;

function kill(){
    transform.position = respawnPoint.position;
    playerHealth -= 1;
}

respawnPoint is just the Transform of an empty gameObject in your scene and here you are just setting your character's position, to its position (the 'jump' is hidden by the fade out). In my game I had multiple spawn points depending on the player's progress, so I had my kill code in the NPC's collision script and I assigned a different spawn point to each NPC.

Hope it helps.

Solved it

    var deathSound : AudioClip;

function OnTriggerEnter (other : Collider) {
if(other.gameObject.name =="Player"){
//destroys player & plays sound
Destroy(other.gameObject);
    audio.PlayOneShot(deathSound);
    //if dead lose a life and respawn
    dead= true;
    PlayerLives.LIVES -=1;
    LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.red, 2.0);
}
}