Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am having trouble finding a way to set a gameobject's position with regards to the screen size. I am building a 2d game that I will be putting on iPhone, iPad, and Android. I need to be able to set the object's position to a percent of the view.

share|improve this question
1  
It would be useful if you could show what you've tried already. Giving us something to build off of, helps you get a better answer. –  Byte56 Sep 19 '12 at 14:54
    
I am not sure where to start. I am checking out camera.WorldToViewportPoint. I think this might be what I need. I just need to figure out how to change it in viewport and give it back in world. –  Bryan Williams Sep 19 '12 at 15:01
    
When you say you need to set the object's position, do you mean you need to set the position to something like 75% to the left of the screen, or do you mean something more advanced like scaling up/bringing forward so that it fills a percentage of the screen? The former is easy, just use docs.unity3d.com/Documentation/ScriptReference/… –  Tetrad Sep 19 '12 at 16:16
    
Yeah, it ended up being viewportToWorldPoint. Thanks for the help guys. –  Bryan Williams Sep 19 '12 at 17:24
1  
You should post an answer detailing your method then. That way future readers can learn. –  michael.bartnett Sep 20 '12 at 2:09

1 Answer 1

The solution ended up being pretty simple. What I had to do is use the conversion of ViewportToWorldPoint.

Camera.main.ViewportToWorldPoint(Vector3(.05, .90, 3));

The decimals are percentages of the screen. and the Z is distance from the camera.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.