Alternating TMPro text color each line?

Hey there, I’m trying to program an accessibility script for my future projects and I’m wanting to create an easier reading experience through alternating the text colour every line.

I want to be able to write the dialogue as normal, relying on overflow and autosize to handle display, which means I want to avoid using Split(‘\n’) as much as possible. Is there a way to detect when a new line has been created and change the line’s color?

Thanks :slight_smile:

There are a bunch of methods related to text exposed in the TextMeshPro classes. All of those are in the project as source code that you can inspect and digest and see what you can get out of it.

It’s probably in classes such as this one:

https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.1/api/TMPro.TMP_TextInfo.html

There might be related linkages in the line breaking code that would prove helpful:

https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.1/api/TMPro.TMP_Settings.LineBreakingTable.html

In the end you might need to do your own splitting, but you can know where to split by studying the above sizing info at runtime.