Search Unity

Question Is it possible to scroll text line by line?

Discussion in 'Scripting' started by Gamadrila, Jul 2, 2022.

  1. Gamadrila

    Gamadrila

    Joined:
    Sep 5, 2021
    Posts:
    142
    I use the standard unity tools "ScrollBar", "ScrollRect", "Content size fitter" and "TextMeshPro". Is it possible to make all the text always move to the height of the line with any type of scrolling? For example, what would never appear on the screen half a line. Smoothness and effects are not needed.
     
  2. richerf3212

    richerf3212

    Joined:
    May 25, 2022
    Posts:
    3
    Scrolling the scrollbar changes the "Pos Y" value of the rect transform of the "Content" GameObject of the ScrollView GameObject.
    Get the height of your text GameObject and subtract/add it to the Pos Y value of the rect transform. This should scroll up just the right amount up or down one increment.
     
    Last edited: Jul 4, 2022
  3. Gamadrila

    Gamadrila

    Joined:
    Sep 5, 2021
    Posts:
    142
    @richerf3212 It was you who wrote the general principle of scrolling. This is how I made the buttons. UNITY has built-in tools to make scrolling. I wrote about them above, they are much better than nothing at all, but still made for mobile phones.
    Now I'm interested in scrolling using the scroll slider, the scroll area and the mouse wheel. There are ready-made scripts in UNITY, but I lack the skills to change something there. I did not find other ready-made solutions or a tutorial. And to reinvent the wheel again, I have no desire yet.