- Home /
The question is answered, right answer was accepted
positioning a gameobject 10 persent of screen
hi guys I ve got a problem with unity would anyone help me plz, my problem is when build my scene the objects that were near the scene edge go away from the camera sight with different resolution , I wanna know that how can put objects in the places such as upper left of screen with any resolution of the monitor thanx alot
Raycast from the corner, where you hit the ground, you place an object (or offset it for half of objects dimensions)
but another question plz what should i write if I want to put the second gameobject just beside the first one that is in the right position ?
var pos : Vector3 = camera.ScreenToWorldPoint(Vector3(Screen.width / 10, Screen.height / 10, camera.nearClipPlane));
var pos2 : Vector3 = (pos + Vector3.right * 0.5);
The "0.5" is assu$$anonymous$$g the radius of your object. Also, for future reference, if you have another question it is always best to make another question.
Answer by Doireth · Jan 31, 2013 at 08:22 AM
The following creates a position 10% of the screen width in from the left and 10% of the screen height up from the bottom. Camera.nearClipPlane is the distance from the camera, this would be dependant on what you are trying to accomplish so you may want to use a different value.
var pos : Vector3 = camera.ScreenToWorldPoint(Vector3(Screen.width / 10, Screen.height / 10, camera.nearClipPlane));
You're missing the new keyword, this should be:
camera.ScreenToWorldPoint(new Vector3(Screen.width / 10, Screen.height / 10, camera.nearClipPlane));
The above example is in uJS which doesn't require the use of the keyword new. You need it for C#, though it will still work if you use the keyword in uJS (which I tend to do!).
Answer by ham · Jan 31, 2013 at 10:01 AM
oah my god an answer an excellent answer in just 10 minutes thanx a lot and even more !!
tick the answer then, so it goes green, and don't post comments as answers