1
\$\begingroup\$

In my game, I have an empty GameObject that has a sprite and a TextMesh as child. I want to access the child (sprite and the text mesh) and turn off the sprite renderer and mesh renderer of the sprite and the text mesh programmatically and be able to then turn it back on, but I don't know how. Some help and/or sample code would be much appreciated. Thanks.

\$\endgroup\$
1
  • \$\begingroup\$ gameObject.renderer.enabled = false/true \$\endgroup\$
    – Raxvan
    Jan 8, 2015 at 13:56

1 Answer 1

3
\$\begingroup\$

You can use 'GetComponent' to access these things. Then, you can edit enable or disable the sprite and mesh renderers.

gameObject.GetComponent<TextMesh>().renderer.enabled = false;

This example will disable the renderer on the TextMesh. Assuming you have a SpriteRenderer on your GameObject (which you refer to as 'Sprite'), to disable that you would use the following code:

gameObject.GetComponent<SpriteRenderer>().enabled = false;

If it is not a SpriteRenderer you can still use the GetComponent method to get the component of your choice and manipulate this component to your likings.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .