- Home /
Gui in same place regardless of resolution
Ok i have an iphone game and the joysticks are done, but i have one issue. If i inset the gui to go to the corner of one resolution, then it will be in a different spot for a different resolution. So basically my question is how can i put the gui of the joystick to be in the two corners no matter what the resolution is, mabye by using inches instead of pixels? Idk
Need particulars. What are you using to draw your joysticks. GUI.DrawTexture()? GUITexture()? Other? How are you currently positioning them?
Actually i dunno, because i just drag and dropped the mobile first person controls.
Answer by Aladine · Dec 07, 2013 at 06:28 PM
Try to look for "Responsive design" to learn more, how ever, here is how i do it : 1-Place your your GUI elements in the editor using absolute positions and size something like
Rect playBut = new Rect(15,20,200,150);
2-calculate what those values represent to the current screen resolution, basically you need to know the percentage of each value related to the screen resolution. 3-once you finished from step 2, you should able to set your element based on the current screen resolution for example :
Rect playBut = new Rect(0,0,0,0);
PlayBut.x += Screen.Width *0.05;
PlayBut.y += Screen.Height *0.02;
PlayBut.Width = Screen.Width/4;
PlayBut.Height = Screen.Height/8;
i hope you get the point from that, it's all about setting your elements always related to your screen resolution
Well, i just used a premade prefab with gui already loaded. And the joystick.js has a lot of stuff in the script. I didnt write it so ii dunno where everything is. Blah blah blah im a stupid unexperienced person i need a bit more of a walkthrough.
LOL!! 1) you are not stupid, stupid people doesn't pass their time learning how to make games ;) 2) does your gui position/size change when you change the prefab transform position/size in the inspector ?? if yes, then create another script, attach it to the prefab, and apply the method i said above
Well the prefab i have, has a main camera, and two joysticks. Those joysticks are a GUITexture component and a joystick script. So to my understanding the GUI and the Script that uses them are seperate. And the script accesses the gui from the component rather than making a gui in a script then using them. I may be totally wrong. But i don't see any gui created in the script.
just to make sure, in the editor, are you using fixed resolution or an aspect ratio ? (it's in the top-left corner of the Game window, am not sure but i guess you should use 16:9 for iPhone)
Im using a fixed resolution but since i have the project set to mobile i get a whole bunch of presets for different iphone screen sizes and resolutions.
Your answer
Follow this Question
Related Questions
Dealing with GUI size on iPhone 1 Answer
How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone? 1 Answer
Scaling position of gameobjects based on screen res 1 Answer
Rendering GUI.Buttons in the middle of the screen 5 Answers
How to make a Horizontal Slider slide between resolutions? 3 Answers