I’m creating a game where I would like it where if the player goes off on one side of the screen, they reappear on the opposite side.
I’m curious as how to set this up in Unity and what the best practise would be.
Many thanks
I’m creating a game where I would like it where if the player goes off on one side of the screen, they reappear on the opposite side.
I’m curious as how to set this up in Unity and what the best practise would be.
Many thanks
you can just change the position.
for example:
if position on the x is > 10
position on the x = -10
That says if you go to the right, you appear at the left.
player position vs screen width and height
basic example:
//somewhere in Update or how ever you deal with movement
if(player.transform.position.x > Screen.width){
// we are past the screen edge... reset to 0 (other side)
player.transform.position = new Vector3(0, player.transform.position.y, player.transform.position.z);
}
The OnBecameInvisible event is the best way that I know. If not the best then it’s definitely the simplest.
I was going to suggest this but he also said they disappear off one side of the screen to reappear on the other.