change alpha of a text like gameobject

hi i have a text and i have with transparency with float but idk how to do it

public class Controlador : MonoBehaviour {

    public GameObject gameovert;
    bool gameover;
    public Color color;

    public void muerto()
    {
        gameovert.SetActive(true);
        gameover = true;
    }


    // Use this for initialization
    void OnGUI()
    {
        Color colorSave = GUI.color;
        GUI.color = color;
     [B]   GUI.Label(new Rect(25, 25, 200, 50), gameovert);[/B]
    }

    // Update is called once per frame
    void Update () {
        color.a = Mathf.PingPong(Time.time, 1.0f);
    }
}
[CODE]

because in the gui label u can use a gameobject only a string :(

The code that fades looks right but you’re passing in a GameObject instead of a string in the GUI.Label.

Something like this would work but not sure if this is what you are trying to achieve:

void OnGUI ()
{
    GUI.color = color;
    GUI.Label(new Rect(25, 25, 200, 50), "Game Over");
}

If you are using the Unity UI Text component in your scene, then you do not use OnGUI().

Instead you would in your update loop change the color property of the Text object.

See the attached unitypackage for an example.

3018608–225451–TextUITest.unitypackage (4.24 KB)

1 Like

tY!!!

1 Like