Why is my code not working?

I am coding in Javascript. This code doesn’t have any errors… but it doesn’t work. The only thing that shows in the log is ‘The player committed suicide’ every time I hit space. Edit: I don’t expect the collision part to work because my player controller does not have a rigid body.

#pragma strict

function Start () {

}

function Update () {
	if(Input.GetButtonUp("Jump")){
		VoluntaryDeath();
	}
}

var dead = false;

function OnCollisionEnter (theCollision : Collision){
	if(theCollision.gameObject.name == "Crazy Cube"){
		Debug.Log("The player was hit by the cube.");
		dead = true;
		}
}

var thePrefab : GameObject;

function SpawnCorpse(){
	var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
	Debug.Log("A corpse was spawned.");
}

function VoluntaryDeath(){
	Debug.Log("The player committed suicide.");
	dead = true;
}

if(dead == true){
	Debug.Log("Dead is now true.");
	SpawnCorpse();
	Destroy(gameObject, 5);
}

You press space and this function is called

function VoluntaryDeath()
{
   Debug.Log("The player committed suicide.");
   dead = true;
}

This sets dead to true and there is nowhere that sets it back to false.

Constant death.

I’m not really sure what you are trying to do, but take a look at this re-hashed code and play with it as you please.

#pragma strict
 
var dead = false;
var thePrefab : GameObject;
	
function Start () {
 
}
 
function Update ()
{
	if(Input.GetButtonUp("Jump"))
	{
		VoluntaryDeath();
	}
		
	if(dead == true)
	{
		SpawnCorpse();
		Destroy(gameObject, 5);
            Debug.Log("The player committed suicide.");
            Dead = false;
	}
}//END OF UPDATE()
 
function SpawnCorpse()
{
	var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
	Debug.Log("A corpse was spawned.");
}
 
function VoluntaryDeath()
{
	Debug.Log("Dead is now true.");
	dead = true;
}
    
function OnCollisionEnter (theCollision : Collision)
{
	if(theCollision.gameObject.name == "Crazy Cube")
	{
		Debug.Log("The player was hit by the cube.");
		dead = true;
	}
}