Child GUITexture/GUIText not going invisible

Hi Guys,

Trying to get a load of children (GUITexture’s and GUIText’s) to go invisible at the start of play. It’s not working.

    void Start()
    {
        SetMenuInvisible();
    }

    void SetMenuInvisible()
    {
        pauseMenu.guiTexture.renderer.enabled = false;

        foreach (Transform child in pauseMenu.transform)
        {
            if(child.GetComponent<GUITexture>() != null)
            {
                child.GetComponent<GUITexture>().renderer.enabled = false;
            }

            if(child.GetComponent<GUIText>() != null)
            {
                child.GetComponent<GUIText>().renderer.enabled = false;
            }
        }

The actual foreach loop works okay, I’ve checked that. However the objects don’t go invisible. There are no errors in the console. I’ve tried child.gameObject.renderer and child.renderer… Nothing seems to work, although the objects are being referenced okay.

The issues slowly giving me tourettes, please help!

Thanks

I’m not sure that GuiText and GuiTexture objects have a renderer component on them. When I add a GUITexture game object to my scene, and attach a script that does:

//js
function Start () {
    transform.GetComponent(GUITexture).renderer.enabled = false;
}

I get:

MissingComponentException: There is no ‘Renderer’ attached to the “UnityWatermark-small” game object, but a script is trying to access it.
You probably need to add a Renderer to the game object “UnityWatermark-small”. Or your script needs to check if the component is attached before using it.
check.Start () (at Assets/check.js:7)

1 Like