Scrolling Textarea in Unity3d – Easy explanation

[tweetmeme source=”neoRiley” only_single=false]I was looking for a quick solution to creating a scrolling textarea in Unity3D and it turned out to be more of a hunt than I thought it should have been.

So, for anyone else trying to figure it out, here’s how it works:

public void LogDebug(string msg)
    traceLog += msg + "\n\n";

    // setting the "y" value of scrollPosition puts the scrollbar at the bottom
    scrollPosition = new Vector2(scrollPosition.x, Mathf.Infinity);

 private Vector2 scrollPosition;
 public void OnGUI()
    // we want to place the TextArea in a particular location - use BeginArea and provide Rect
    GUILayout.BeginArea(new Rect(60, 5, 250, 250));
    scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width (250), GUILayout.Height (250));

    // We just add a single label to go inside the scroll view. Note how the
    // scrollbars will work correctly with wordwrap.
    GUILayout.Label (traceLog);

    // End the scrollview we began above.
    GUILayout.EndScrollView ();

Have a bandit day!

    • David
    • September 17th, 2010

    Hey Neo,

    Trench Run 2.0 rocks!!!

    What ideas are on the table for the next update? And how soon if you were to guess?

    Your fan,

    • David
    • September 27th, 2010

    Hey Neo,

    Just checking to see if you got my question.


    p.s. Could you include the ability to go hyperspace and the asteroid field:)

    • David
    • September 27th, 2010

    Screen orientation toggle would also be nice:-)

  1. Right now, we’re seeing how 2.0 pans out in sales before making decisions on another version update 😉

    as for the suggestions, those are definitely on the list!

      • David
      • September 27th, 2010

      Hey Neo,

      You could continue to develop and make profits for this game by offering more in app purchase options. Many who already have the game would gladly pay for an “empire strikes back” pack or a Return of the Jedi pack.
      The key to continue making this a profitable game lies in creating more in app purchases:-)
      Pass this along to your co-developers and THQ Wireless!

      As always, YOU ROCK!!


  2. Thank you very much !!!
    This code has been very useful for me, I was in trouble !!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s