Find y position of player
I already have a player Player, but I am curious how to find the x position, so that in case the player falls out of the world somehow, it automatically teleports the player back to where the player spawned. I want something like this:
if ((player location y) =< -1) {
//do something
}
You could use (gameobject.transform.position.y).. Do you plan to put this check in the Update()? But You'd be better off adding a collider around / below your "workable" area...
Answer by Neolith998 · Jan 08, 2016 at 08:25 PM
You can simply do
if(player.transform.position.y <= -1)
{
//do something
}
Since you're working on respawning the player once he falls off the world, I highly recommend putting this inside Update(), since you always have to check if the player is within the world's bounds.
Have fun!
Thanks! Also, just curious, how would I teleport the player somewhere?
Your answer
![](https://koobas.hobune.stream/wayback/20220612055347im_/https://answers.unity.com/themes/thub/images/avi.jpg)