Force object position

I want to make a script so when the player falls off the map the scene gets reseted…For some reason Application.loadLevel doesn’t work so i wanted to just change the player’s position so he is on the map again.I tried using this :

#pragma strict

var X : float;
var Y : float;
var Z : float;



function Start () {

X = transform.position.x;
Y = transform.position.y;
Z = transform.position.z;


}

function Update () {

}

function OnTriggerEnter(other : Collider){

transform.position.x = X;
transform.position.y = Y;
transform.position.z = Z;

}

but it doesn’t work?! Any help would be nice

I am assuming that the player is not the trigger. I assume the player falls into the trigger. Therefore, your solution would not work. The OnTriggerEnter would need to be on the trigger object. What I usually do for this sort of thing is create an empty game object where I want the character to spawn. I then create a script similar to this (note that I am not good with JS, please understand the intention and not the strict syntax):

var spawnPoint: GameObject;

function OnTriggerEnter(other : Collider)
{
    if(other.tag == "Player")
        other.gameObject.transform.position = spawnPoint.transform.position;

}

The spawn point will need to be dragged over to the script component in the editor. The player will need to be given the tag “Player”. Then, whenever the player falls in, they get moved to the spawn point.