Hello, guys! I’ve been going through some problems when it comes to screen resolution because it seems I simply can’t create the GameObject on the right position depending on what screen resolution I’m playing.
An example, “Free Aspect”:
And “Maximize on Play”:
And the problem persists in every resolution I tested after building the game. It seems the game only works properly when running in Free Aspect.
Consider using Camera.ViewportToWorldPoint if you want the GameObject to be created in a position relative to the Camera’s viewport rectangle despite the screen size.
Viewport space [for the Camera] should be within the range of 0 and 1 on both the X and Y axis. So Screen.width/-68.59 for example might be far outside of the range of the screen (if width is 600 pixels for example, 600/-68.59 is outside of the range of 0 and 1).
Same thing for Screen.height/-84.85f
You also shouldn’t need to call it twice for screen width and screen height.
It’s extremely difficult to say without seeing your code. There could be a myriad of reasons as to why your Sprite vanishes.
-The Sprite is rendered on the incorrect layer (unlikely if your scene was already setup properly)
-The Sprite is being hidden by other objects because its Z value is under another object on the same sorting layer (likely, especially if you are using the code I supplied as a test and didn’t modify someDistance to a value suitable for your needs)
-Something is disabling the Renderer of your GameObject with the Sprite attached to it.
But I’m merely guessing. I have no idea unless I see how you’ve implemented the positioning of your GameObject and if I know what other Images are on the same Sorting layer as your sprite.
I’m willing to bet that the Z value (someDistance) is not properly set.