How to make rainbow text in Unity games
A guy in FB kept trying to ask me
how to make colored text or colored FONTS.TTF blah blah in Unity game like
Philly made in Racing games. TTF file can't have colors in it, It just a font
file. Isn't he an idiot?
I decided to research but i couldn't
find anything useful. Coding that way is too complicated I guess... I came with
an idea that I could make rainbow text using <color> tag like I did in BB
code in forums, and i just found a HTML rainbow text generator tool that can be
used.
Ok let's get started.
I'm no coding expert so i'll teach
you the lazy method to make colored text look like rainbow in Unity editor.
Install Unity and create a new
project. I won't explain how to do that. There are lot of tutorials how to use
Unity.
Create a new script from the Create
menu at the top left of the Project panel or by selecting Assets > Create
> C# Script from the main menu
Visit http://rainbow.arch.scriptmania.com/tools/rainbow_text/ and create your own rainbow text.
Look at Output HTML Code, this is what we need
<HTML><FONT
COLOR="#FF0000">t</FONT><FONT
COLOR="#FF4600">h</FONT><FONT
COLOR="#FF8C00">i</FONT><FONT
COLOR="#FFD200">s</FONT><FONT
COLOR="#FFff00"> </FONT><FONT COLOR="#B9ff00">i</FONT><FONT
COLOR="#73ff00">s</FONT><FONT
COLOR="#2Dff00"> </FONT><FONT
COLOR="#00ff00">a</FONT><FONT
COLOR="#00ff46"> </FONT><FONT
COLOR="#00ff8C">r</FONT><FONT
COLOR="#00ffD2">a</FONT><FONT
COLOR="#00ffff">i</FONT><FONT
COLOR="#00D2ff">n</FONT><FONT
COLOR="#008Cff">b</FONT><FONT
COLOR="#0046ff">o</FONT><FONT
COLOR="#0000ff">w</FONT><FONT COLOR="#2D00ff">
</FONT><FONT COLOR="#7300ff">t</FONT><FONT
COLOR="#B900ff">e</FONT><FONT
COLOR="#FF00ff">x</FONT><FONT
COLOR="#FF00D2">t</FONT></HTML>
but WAIT! This code
won't work in Unity. We need to edit the code for Unity support. Open Notepad++ or other programs and
edit the code.
I'll use Notepad++. Click Search -> Find in Files. Click Replace
tab.
Replace all </FONT>
with </color>
Replace all FONT(space)
with nothing.
Replace "
with nothing
Remove <HTML></HTML>
Now we have a good working code for
Unity
<COLOR=#FF0000>t</color><COLOR=#FF4600>h</color><COLOR=#FF8C00>i</color><COLOR=#FFD200>s</color><COLOR=#FFff00>
</color><COLOR=#B9ff00>i</color><COLOR=#73ff00>s</color><COLOR=#2Dff00>
</color><COLOR=#00ff00>a</color><COLOR=#00ff46>
</color><COLOR=#00ff8C>r</color><COLOR=#00ffD2>a</color><COLOR=#00ffff>i</color><COLOR=#00D2ff>n</color><COLOR=#008Cff>b</color><COLOR=#0046ff>o</color><COLOR=#0000ff>w</color><COLOR=#2D00ff>
</color><COLOR=#7300ff>t</color><COLOR=#B900ff>e</color><COLOR=#FF00ff>x</color><COLOR=#FF00D2>t</color>
In Unity editor, open the script you
just created. If you have Visual Studio installed, it will launch Visual Studio
instead.
Remove the following code
// Use this for initialization
void Start () {
}
// Update is called once per
frame
void Update () {
}
Add the following pre-coded GUI I
made. It is for testing text
void OnGUI()
{
GUI.Box(new Rect(10, 10, 500, 90), "");
GUI.Label(new Rect(25, 25, 1000, 500), "");
}
Add your rainbow text code under "". The final code will look like
void OnGUI()
{
GUI.Box(new Rect(10, 10, 500, 90), "");
GUI.Label(new Rect(25, 25, 1000, 500), "<COLOR=#FF0000>t</color><COLOR=#FF4600>h</color><COLOR=#FF8C00>i</color><COLOR=#FFD200>s</color><COLOR=#FFff00>
</color><COLOR=#B9ff00>i</color><COLOR=#73ff00>s</color><COLOR=#2Dff00>
</color><COLOR=#00ff00>a</color><COLOR=#00ff46>
</color><COLOR=#00ff8C>r</color><COLOR=#00ffD2>a</color><COLOR=#00ffff>i</color><COLOR=#00D2ff>n</color><COLOR=#008Cff>b</color><COLOR=#0046ff>o</color><COLOR=#0000ff>w</color><COLOR=#2D00ff>
</color><COLOR=#7300ff>t</color><COLOR=#B900ff>e</color><COLOR=#FF00ff>x</color><COLOR=#FF00D2>t</color>
");
");
}
Save it
To view your GUI, make sure you drag
and drop your script on Main Camera.
After that, press the blue Play button to start.
Congrats, you just make your first
rainbow text in Unity, lol.
You can make rainbow text in Unity games
but I have no idea how. Must be very skilled programmer.
Comments
Post a Comment