Scaling GUI.TextArea with Screen Size

后端 未结 2 713
无人共我
无人共我 2020-11-30 16:11

i\'m trying to scale a GUI.TextArea.

the code block works in OnGui function. But when i change screen size , the textArea won\'t be on correct position and size.

2条回答
  •  情深已故
    2020-11-30 16:23

    The UI system in unity is very easy to use...

    1) click add canvas .. select "scale with screen size"

    Important!!!!!!!!!!!!!

    It is critical to select "scale with screen size".

    (Note that this is in the "Canvas Scaler" section - it is NOT in the "Canvas" section.)

    (2017 - note they recently changed the wording from "space" to "size"...)

    Unity accidentally set the WRONG DEFAULT OPTION on that menu.

    Until they fix the problem, it is essential to remember to select "scale with screen size".

    The other options are irrelevant and almost never used.

    2) click "Add Button", or add any element you want: panel. scroll view, slider, etc.

    You're completely done.

    It's that easy.

    For a given item: to achieve what you say about POSITION, just do this ...

    select the option relevant to you, probably middle one.

    In your script have

      public Text hello
    

    That will create a slot (labelled "hello") in your Inspector panel for that script.

    be sure to drag the physical .Text unit (ie, underneath "Canvas") to that slot in the Inspector. To set the text, in code, is trivial:

        hello.text = "some text here"; 
    

    it's that simple. You can set the size, shape, position, etc of the type in the editor, what you see is what you get.

    Be sure to set the following items ...

    ... as you need them. Cheers.

提交回复
热议问题