0

I am currently in the progress of designing the UI for my little coding game made in the current version of Unity and want to show line-numbers for the code editor. My problem is that I somehow need to get the Text object for drawing those numbers to "scroll" alongsside the Text of my InputField in order for it to make sense.

Is there any variable on the InputField that contains information about how far it scrolled? Is there a function I can call? Do I have to connect both the InputField and the Text somehow?

Simplified hierarchy If I were to add one more line the InputField would scroll down, but the lines would not change.

1 Answer 1

1

Install TextMeshPro package from the package manager, it has a built in input field that supports scrolling out of the box without any coding.

It is also the future of unity's text.

4
  • Thanks for the reply! I actually took a quick look into that but scrapped the idea, because the kind of Text I had to use didn't support the font I am using. I'll look into it again now though! (I'll mark your answer as correct once I've got it working ;) )
    – cegredev
    Oct 19, 2019 at 11:25
  • You can use any font you want with TMPro, following the official guides: youtube.com/watch?v=eXhfygRgIVY
    – ChoopTwisk
    Oct 19, 2019 at 11:29
  • Found the Font Converter under "Window --> TextMeshPro --> Font Asset Creator" and even got the scrollbar working. But I'm not sure if I'm doing it wrong or you misunderstood my question: The line numeration is done in a seperate Text object that is not controlled by the input field. Therefore the scrollbar only moves the text affected by the InputField and not the line text.
    – cegredev
    Oct 19, 2019 at 11:50
  • Okay, it was me who misunderstood. The line text was hidden by the mask of the Text Area which made me think it didn't work. Thank you so much!
    – cegredev
    Oct 19, 2019 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.