- Home /
Newbie question 2d positioning and moving
Hello, I am making a 2d mobile game, c# scripts. I have defined a picture png (a smiley) that is in a plane. Because it is a mobile game the game view it is defined as Free Aspect.
I have placed the smiley picture in the center of the view.
I want in the start() to place the smiley at the bottom middle. And to be more specific 10% higher than the bottom in the middle and if possible take in account the smiley picture size.
And after I press the smiley picture I want it to go up to middle (10% from the top).
I just don't understand how to figure it out the width and height of the view, I know it is not Screen.width or .height
Let's say w contains the width and h the height so I am in liberty to something like transform.position w 0.5f, h 0.1f (or something that includes the height of the picture) and I don't know what to do with z
Thanks in advance
Daniel
Even in 2d, screen coordinates never equal world coordinates. Use the many functions of the Camera component to random between the two spaces.
Answer by JoaoOliveira · Jan 28, 2014 at 09:51 AM
Use viewport coordinates. For instance, this places your object in the bottom left corner of the screen:
Camera.main.ViewportToWorldPoint(new Vector3(0,0,gameObject.transform.position.z));
And this places your object in the top right of the screen:
Camera.main.ViewportToWorldPoint(new Vector3(1,1,gameObject.transform.position.z));
Answer by ideaman · Jan 28, 2014 at 10:05 AM
Thank you very much all for your help.
I've fixed the problem
Daniel