x


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();
more ▼

asked Nov 15 '10 at 06:31 AM

Showken gravatar image

Showken
186 35 45 55

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

Nov 15 '10 at 06:42 AM matyicsapo

have already showed the code,think you!

Nov 16 '10 at 06:17 AM Showken
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest
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.

more ▼

answered May 10 '11 at 11:34 AM

FreeTimeDev gravatar image

FreeTimeDev
408 14 20 30

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Nov 16 '10 at 07:15 AM

matyicsapo gravatar image

matyicsapo
659 12 15 27

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3816
x915
x502
x85

asked: Nov 15 '10 at 06:31 AM

Seen: 5876 times

Last Updated: Nov 16 '10 at 06:16 AM