Gradient text in Unity

Mopsicus
1 min readMay 13, 2020

There is an own gradient text option in TextMeshPro package. But it doesn’t work properly for my task. TMP gradient applies for each character in text, and it looks like this:

Before (not good)

But for my task, gradient should be filed for all text, from left to right. So, I’ve wrote custom script, that gets gradient colors form text component and apply it for all text. And now it looks like this:

After (good :)

The trick is simple: divide gradient for characters count and then, in order, apply our ranges for each characters.

Source code

This article is translation from my blog: https://mopsicus.ru. I will try to translate and write here more often if you like post as this.

--

--