- Home /
Fit GUIText in every resolution
Ok, so this may be a very duplicated question, but i havent found an answer. Basically what i want is a way to make my GUIText stay, regardless of what. So if the guitext is at the bottom center and i change the resolution, the guitext is still at the bottom center.
I know i have to use Screen.width and height but i just can't figure it out. Ive been working with it all day and my brain just cant think straight. Hope anyone can give me a simple solution to my problem. :-)
Answer by zharik86 · Feb 17, 2014 at 07:03 PM
Watch my answer to your pregoing question answers.unity3d.com/questions/642044/android-screen-size-script-not-working.html
Answer by ivan2532 · Feb 17, 2014 at 07:13 PM
You can make a GUI.Box without texture... And implement this code:
var guiSkinForBox : GUISkin;
function OnGUI()
{
GUI.skin = guiSkinForBox;
GUI.Box(Rect(0, 0, Screen.width, Screen.height), "Text here...");
}
Good luck!
Doesn't help, the screen gets darker when using it .. Isnt there a way to just do it with a normal guitext?
Of course it gets darker, its a Gui.Box in the entire screen, I will wrote an answer :p
But i don't need a guibox that makes the screen darker.. I want a guitext .. D:
Answer by RafaelCN · Feb 17, 2014 at 07:33 PM
Ok so you need a "responsive" layout, I have made an API to provide me that, and I will show a little functions to show to you how to do that.
public bool createButton(float left, float top, float width, float height, String value)
{
return GUI.Button(new Rect((screenWidth-screenWidth)+left, (screenHeight-screenHeight)+top,
width, height), value);
}
ScreenWidth and ScreenHeight:
//Get the screen width and height
public int getScreenWidth { get; set; }
public int getScreenHeight { get; set; }
private int screenWidth = Screen.width;
private int screenHeight = Screen.height;
What the code does? The function that I've created a function to create a Button, the function takes the size of the screen, and make a button with: the size of the screen - the size of the screen(it makes the screen positioning 0) more the position that you have inserted on the function.
@NinjaRubberBand you can make your own function to make exactly what I've done :D
Ok im really confused.. Why isnt it possibly to just make a simple guiText and make it stay at every resolution???
It's easy as I said, create your function createGuiText(arguments...)
, I've made a createLabel(arguments...)
to create a Label on the screen for me, it works perfectly, just think a little more, when the difficult comes, you just need a motive to pass through it!
Its really hard to see what this is when you are 15 years old and don't have english as mother language. And im only 2 months into scripting so there is a lot i really don't understand.
It would be very nice if you could make a scene where you showed it. Just a fast setup. I just cant see how i can use this, its always easy when you understand what is going on.
I began to develop when I was fourteen, and as you, I don't have english as a mother language. I used to have a lot of trouble with that, and then I realize that I have to learn how to program first, improve your logic first, methods, arrays, pointers, class, OOP. Ok, let's focus, I've have two classes, one in the camera, and one is my API that provide me the functions that i said. Here is a sample of what my API does with the script on the camera
How I use my API:
_screen screen = GetComponent<_screen>();
_systemInfo system = GetComponent<_systemInfo>();
screen.createLabel(10, 10, 220, 50, "OS: " + system.OperatingSystem);
screen.createLabel(10, 50, 220, 50, "Processor: " + system.Processor);
screen.createLabel(10, 100, 220, 50, "Graphic Card: " + system.GraphicCard);
screen.createLabel(10, 140, 220, 50, "Graphic Card $$anonymous$$emory: " + system.Graphic$$anonymous$$emory);
screen.createLabel(screen.getScreenWidth-100, 10, 200, 20,
"Width: "+screen.getScreenWidth.ToString());
screen.createLabel(screen.getScreenWidth-100, 30, 200, 20,
"Height: "+screen.getScreenHeight.ToString());
It is a little bit complicated if you are novice in program$$anonymous$$g, but it became understandable when you practice your OOP, and method creation...
Hope it help :D
Your answer
Follow this Question
Related Questions
Make buttons visible in the editor? 2 Answers
How to make my game fit into my droid? 1 Answer
How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers
Pick sensible resolution for FullScreen Mac App 2 Answers
Screen.SetResolution doesn't work when the game starts windowed? 0 Answers