I have no idea why this code isn't working! it should. I have a character and a on that character I have a respawn.js. below is the code for it. now, it was originally working when I was using the update function as posted below, but when I take that out and put in the OnControllerColliderHit function (also listed below) it doesn't work anymore. you'll see 2 debug.logs in the forceRespawn function. the first debug gives me this:-362.9575 (transform.position.y) the second gives me this: 579.3809 (transform.position.y after the respawn but, my character doesn't actually move at all!). is there something about needing to move the transform in the Update function or what??
static var startingspawnpointx;
static var startingspawnpointy;
static var startingspawnpointz;
function Awake()
{
startingspawnpointx = transform.position.x;
startingspawnpointy = transform.position.y;
startingspawnpointz = transform.position.z;
}
function Update()
{
//check if transform (what this script is connected to) fell off platform and respawn it.
if(transform.position.y < -2000)
{
forceRespawn();
}
}
function forceRespawn()
{
Debug.Log(transform.position.y);
transform.position.x = startingspawnpointx;
transform.position.y = startingspawnpointy;
transform.position.z = startingspawnpointz;
Debug.Log(transform.position.y);
}
function OnControllerColliderHit(hit: ControllerColliderHit)
{
if (hit.gameObject.name == "Respawn")
{
Debug.Log("about to");
forceRespawn();
Debug.Log("respawn");
}
}