Search Unity

Removing a component

Discussion in 'Scripting' started by Richard_B, Jun 17, 2006.

  1. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Ummm... simple question - how do I deactivate (or remove) a component of a gameObject - can't find anything in the docs or forum :(

    thanks,
    Richard.
     
  2. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    It's called Object.Destroy()

    d.
     
  3. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    but I don't want to destroy the whole object - basically just deactivate a component (the mesh renderer actually).

    thanks,
    Richard.
     
  4. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    This trick to understand is that a Component is also an Object. So Object.Destroy() applies. Try it.

    d.
     
  5. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Lol!! I'll give it a try!
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    And if you want to keep the MeshRenderer around then you can just use :

    renderer.enabled = false;
     
  7. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Well what do you know - both methods work! doh!

    Thanks!!

    Richard.