How to change Text Color by Script | Unity

How to change Text Color by Script in Unity

How to change Text Color by Script | Unity


in this Tutorial i will show you how to change color of a text via script in unity engine , change color on Start or By Button.

 In Unity editor :

  1. create a new text  ,  and add a new script to the text , name it like you want  
  2. open the script

In Script :

  • add a new library 

using UnityEngine.UI;


  • Add variable of the Text :

public Text myText;


  • to change the color of the text you have to use this line :

myText.color = Color.red;

How to change color in Start :

// Start is called before the first frame update
    void Start()
    {
        ChangeTextColor();
    }

public void ChangeTextColor()
    {
        myText.color = Color.red;      
    }

How To change color by Button

watch the video below and follow the steps.





unity change text color on hover unity color text unity change color in script change gameobject color unity c# unity change ui text via script change color textmeshpro unity change material color unity change canvas text in script

...