Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Using GUIStyle parameter in GUI.TextArea problem

Discussion in 'Scripting' started by ilya1966, Dec 2, 2010.

  1. ilya1966

    ilya1966

    Joined:
    Nov 26, 2010
    Posts:
    2
    Hi, everybody!
    I try to create a edti control with my own textures. I use well known code like:

    //Scroll position and text members
    private int scrollPosition = 0;
    pribate string mytext = "";
    Rect visibleRect = new Rect(0, 0, 100, 200);

    protected void OnDraw()
    {
    //Scrolling area calcualtion
    Rect fullarea = new Rect(visibleRect.xMin, visibleRect.yMin, visibleRect.width - 20, visibleRect.height * 3);

    //Starting scroll view
    scrollPosition = GUI.BeginScrollView(visibleRect, scrollPosition, fullarea);

    //Creating Text Area
    mytext = GUI.TextArea(fullarea, mytext, 500);

    // End the scroll view that we began above.
    GUI.EndScrollView();

    }

    This code is working pretty well. A problem starts when I try to create custom text are. Instead of

    //Creating Text Area
    mytext = GUI.TextArea(fullarea, mytext, 500);

    I use code like this:

    GUIStyle textAreaStyle = new GUIStyle();
    //textAreaStyle.font = font.font;
    textAreaStyle.focused = new GUIStyleState();
    textAreaStyle.focused.textColor = Color.black;
    textAreaStyle.alignment = TextAnchor.UpperLeft;
    textAreaStyle.wordWrap = true;
    textAreaStyle.normal.textColor = Color.blue;

    GUI.skin.settings.cursorColor = Color.black;

    mytext = GUI.TextArea(fullarea, mytext, 500, textAreaStyle);

    Now clicking Enter keyboard key doesn't affect on the text: no new line is inserted into the text. I tried to change different parameters of textAreaStyle variable but nothing helps. Please, help me to resolve this problem. How can I create custom TextArea which accepts KeyCode.Return. Thanks in advance