3
\$\begingroup\$

I want to remove a Sphere Mesh Renderer component from a certain gameobject. I want to do this in a script. How do I do it? I do not want to destroy the sphere itself, just the component

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

You can Destroy the component.

Be careful about which object you destroy, though. If you pass a GameObject to Destroy, you will destroy the entire thing. To destroy the component, you must pass a reference to that component specifically.

//example: destroys the MeshRenderer attached to this GameObject
var sphereMesh = GetComponent(MeshRenderer);
Destroy(sphereMesh);
\$\endgroup\$
0

You must log in to answer this question.

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