- Home /
gui position of Screen relative position
I have set a gui position with "Screen.width*,Screen.height *",but when I resize the Screen window,the gui didn't move to relative position .why?
GUI.BeginGroup(new Rect(Screen.width-470, Screen.height-66, 470, 66));
GUI.skin=tiaoskin;
GUI.Label(new Rect(0,15,470,51),"");
GUI.skin=geoskin;
if(GUI.Button(new Rect(10,25,75,36),""))
{
MoveToArea(geoposition);
}
GUI.skin=touskin;
if(GUI.Button(new Rect(90,25,58,36),""))
{
MoveToArea(touposition);
}
GUI.skin=cityskin;
if(GUI.Button(new Rect(160,25,53, 36),""))
{
MoveToArea(cityposition);
}
GUI.skin=ecoskin;
if(GUI.Button(new Rect(230,25,60, 36),""))
{
MoveToArea(ecoposition);
}
GUI.skin=humskin;
if(GUI.Button(new Rect(310,25,65, 36),""))
{
MoveToArea(humposition);
}
GUI.skin=helpskin;
if(GUI.Button(new Rect(390,32,19, 24),""))
Movehelp(false);
if(isvoice)
{
GUI.skin=voiceonskin;
if(GUI.Button(new Rect(430,32,31, 24),""))
{
voicetemp.audio.mute=true;
isvoice=false;
}
}
else
{
GUI.skin=voiceoffskin;
if(GUI.Button(new Rect(430,32,31, 24),""))
{
voicetemp.audio.mute=false;
isvoice=true;
}
}
//
if(isflash)
{
GUI.Label(new Rect(225,0,200,30),flashimg);
}
GUI.EndGroup();
i don't know about others but I'd need to see the actual gui command's code to be able to tell the problem
Answer by matyicsapo · Nov 16, 2010 at 07:15 AM
The (0,0) point in GUI is the top-left corner.
Your buttons move horizontally though maybe not the way you want. I suggest you change your magic numbers atleast for the values of the group to public variables atleast or do somekinda calculation like where is the center of the screen or whatever.
But the reason your controls don't move vertically is that the Screen.height
may change, but you always subtract the same value from this changing Screen.height
. Of course 500-66=434 and 200-66=134 so you that it should be at a different position. But the maximum of Screen.height
is always the bottom of the screen. And you always subtract the same value 66 in your example. That is it will always be 66units away from the bottom of the screen. Which is true as you can see too.
Hope that was clear enough that it helped.
Answer by FreeTimeDev · May 10, 2011 at 11:34 AM
GUI.BeginGroup(new Rect(Screen.width-470, Screen.height-66, 470, 66));
Screen.width:
0% = Left side. 100% = Right side.
Screen.height:
0% = Top. 100% = Bottom.
If you ALWAYS want your group to be in a specific spot on screen regardless of resolution you cannot use absolute numbers in your code. Your code should probably look something like:
GUI.BeginGroup(new Rect(Screen.width*<Some Number>, Screen.height*<Some Number>,
Screen.width*<Some Number>, Screen.height*<Some Number>));
(Some Number is between 0 and 1, like .5)
This is because, obviously, different resolutions have a different number of pixels. So when you say you want it 500 pixels from the right side of the screen that's almost on the left side of the screen in a Web Player, or middle-right side in a Full screen application.