- Home /
Respawn player at different Spawnpoints
Hi there! I'm trying to make my player respawn at a fixed spawnpoint. I want to have different spawnpoints along my level... here is my question: how can i pick up the cordinates of a taged gameobject? thanks
here is my script:
var spawnp=0;
function dead() { if(spawnp == 0) { transform.position.x = 0; transform.position.y = 12; transform.position.z = -9; transform.rotation.y = 0; } if(spawnp == 1) { transform.position.x = 0; transform.position.y = 26.0515; transform.position.z = 121.4297; transform.rotation.y = 0;
}
}
Healthcontrol.LIVES -=1;
}
Answer by poncho · Mar 18, 2011 at 02:35 PM
to get the coordinates of a gameobject's transform you need its position property like
GameObject.Find("MyObject").Transform.Position
the Position property is a Vector3 object
hope this is the answer you are looking for
thanks, but it didn't work:
Assets/scripts/respawnPlayer.js(68,49): BCE0034: Expressions in statements must only be executed for their side-effects.
what i meant was, to put your info in that order, like if(spawnp ==0){GameObject.Find("YourTransformTo$$anonymous$$ove").Transform.Position = new Vector3(0,12,-9);} if(spawnp ==1){GameObject.Find("YourTransformTo$$anonymous$$ove").Transform.Position = new Vector3(0,26.0515,121.4297);} note that the name "YourTransformTo$$anonymous$$ove" should be replaced for the name of the transform you want to change its position like cube1, hero, mainchar or the name you used, i thought the answer i gave, was intuitive, my bad.