Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED]How do I program a scrollbar?

Discussion in 'Scripting' started by Marjo_Borestag, Jul 27, 2014.

  1. Marjo_Borestag

    Marjo_Borestag

    Joined:
    Aug 14, 2013
    Posts:
    14
    Hello everyone. I am making chat for my game and wanted to know how could I implement a scrollbar for my chat window. Basically there's max messages and at start there will be 0 messages. So the scrollbar would be full height, but as more messages are being typed it should decrease in size. Also how do I make the text area scrollable?

    I found out all of that myself. My tip: use Scrollview with some very smart Scrollview's height changing using functions like CalcHeight and CalcSize
     
    Last edited: Jul 30, 2014
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Tell me that you googled "Unity Scrollbar", and looked at GUI.VerticalScrollbar?
     
    Magiichan likes this.
  3. Marjo_Borestag

    Marjo_Borestag

    Joined:
    Aug 14, 2013
    Posts:
    14
    I did. But I am asking how to program the logic of it, like make it scroll the textarea for example.
     
  4. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    if you don't want to use Unitys built in VerticalScrollbar or any other GUI solutions like NGUI etc then it won't be to hard to make a crappy version yourself. But I must ask; why don't you want to use Unitys GUI? or another package?

    But anyways..

    you'll want to do is test to see if the mouse is over / clicked on your 'slider', if it is set it to the position of the mouse to make the actual slider scroll part. And obviously clamp it's y position to whatever you wish..

    Then for your object to scroll you'd want to set its position to the y value of the slider or something similar, that won't do it completely, you'll want to add some more logic to actual scroll properly, but that's the base so you could play around with it