Search Unity

i cant change text color in prefab

Discussion in 'Editor & General Support' started by IndleStudios, May 12, 2018.

  1. IndleStudios

    IndleStudios

    Joined:
    Oct 12, 2017
    Posts:
    9
    Hey guys. I'm having a very strange problem.

    I have created a prefab containing only one Text.

    I did the following function

    Code (CSharp):
    1. public void LoadModel (int damage)
    2.      {
    3.          damageTest.GetComponent <Text> (). color = Color.red
    4.  
    5.          Instantiate (damageTest, enemy);
    6.      
    7.          damageTest.GetComponent <Text> (). text = damage.ToString ();
    8.      }
    it takes the damage and shows it in the Text. this function will be modified in the future.
    and to test I put the color change in that function ..

    so the text changes according to the damage .. but the color does not change .. and ja vis several tests with several prefabs and none of them, I can not change the color ..

    if the text is a gameobjet of the scene it does not have any problem. everything works fine .. but from the moment it turns a prefab the color never changes !! Can someone tell me why?