Hi, I am new to Unity and I am have having a difficult time understanding these two functions. I tried converting points from screen to world to adjust the position of GUI Texture on the screen but the texture world point vector3 returned was out of the screen. (I have read unity documentation and other answers and I was hoping it would work as I understood it). What I did was
float x = 20;
float y = Screen.height/2 - 30; // screenheight/2 is because my device is retina
Vector3 coinsPos = new Vector3 (x, y, 0f); // this should be top left of screen
Debug.Log ("WORLD - coinsPos :" + Camera.main.ScreenToWorldPoint (coinsPos));
// Output is WORLD - coinsPos :(-2.4, -1.1, -10.0) - which is outside the screen
More over, I tried to convert a vector3 with float values to screen points and then back to world points. Shouldn’t it give same result as initial vector ?
Vector3 worldTestVect = new Vector3 (0.17f, 0.96f, 0f);
Debug.Log ("worldTestVect :" + Camera.main.WorldToScreenPoint (worldTestVect));
// Output is : worldTestVect :(89.0, 175.4, 10.0)
Vector3 screenTestVect = Camera.main.WorldToScreenPoint (worldTestVect);
Debug.Log ("screenTestVect :" + Camera.main.ScreenToWorldPoint (screenTestVect));
// Output is : screenTestVect :(0.2, 1.0, 0.0)
I would be very grateful if some one could help me understand this please. I am developing for mobile screens(in case it matters).
Btw I have tested it on both device and unity console.
Edit : The device I am using and resolution selected in unity is for iphone5, which have screen resolution of 320x568.