Friday, 15 March 2013

How to utilize Screen.Width/height? --Unity3d -



How to utilize Screen.Width/height? --Unity3d -

i trying randomly instantiate things within screen in unity 2d

i tried utilize screen.width , screen.height objects appearing way off screen. realized because screen.width/height returns length in pixels , unity goes own unit.

for example, didn't work. bomb appears way off screen

var randomx = random.range(-screen.width/2, screen.width/2); var randomy = random.range(-screen.height/2, screen.height.2); var spawnpoint:vector2 = new vector3(randomx , randomy); instantiate( bomb, spawnpoint, quaternion.identity );

is there way convert pixels unity units?

there sure is, utilize screentoworldpoint.

note api informs bottom left of screen 0,0, want alter randomx/y accordingly.

unity3d

No comments:

Post a Comment