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