- Home /
Spawn objects in random visible location
Hi,
I'm trying to figure out how to get the bounds of "what is currently visible". I have a perspective camera and a Screen - Space overlay canvas, and I want the bounds of the visible world : what I see when I play the game. I already tried a lot of stuff written in that forum, with Screen.width, Screen.Height, but also camera.pixelWidth, camera.pixelheight, camera.width, camera.height, and various conversions with Camera.main.ScreenToWorldPoint. Screen and camera sizes give me something like 900 in width and 400 in height.
None of that work. What does it mean ? => Basically, when I pause the game in unity, the "manual" bounds I observe (meaning in which my object is still visible) is about -14; 14 in width and -5; 5 in height.
When I try to convert, it always gives me (0;1) because I don't provide the Z argument because I have no idea what to put there.
If I don't convert using WorldToScreen or the opposite, it then gives me values between 0 and 900 for width and 400 for height, which is not in the scale -14;14 I got manually by observing in the inspector while pausing the game.
So how come I got such big values or weird values with conversion ? I don't want to put hardcoded value..
Any thoughts ?
Thanks.
Your answer
Follow this Question
Related Questions
Help with repositioning object to a random position in the FOV 1 Answer
Camera Viewport Height - Horizontal Transition 0 Answers
Spawning Enemies randomly within the screen 1 Answer
spawning position problem 0 Answers
Spawns More then it is possible to spawn? 168 instances for a limit of only 2 per carrier? 0 Answers