Height and width (pixels ) vs X and Y (axis units)

Hello,

I created a player sprite and I don’t want it to move any further than camera borders are. I can get Screen.width and Screen.height values but I don’t know how to use those to reposition or make a comparison with translation.position.x nor .y nor .z. I know Screen.height and .width are integer values which we all know as pixels but i don’t know how to make a connection with xyz axis units.

How can I limit player sprite movement if I know dimensions of a screen?

You want to utilize the camera class. It has functions to convert screen coordinates to world coordinates and vice versa.

WorldToScreenPoint seems to work great in the editor but as soon as you get onto an iOS device its coordinates are offset rather badly. Seems to be a bug in Unity possibly?

Maybe WorldToViewportPoint is better suited for your needs. It takes into account the viewport of the camera.