- Home /
Oh the HUMANITY!! How do I deactivate one game object and then activate another?
Here's my issue. I'm making a game that requires something that I cannot find on the forums, the Unity manual or on YouTube. I have the need to be able to have many GameObjects that all have scripts. What I need to do is use my mouse to click on the object in game mode and deactivate it. Then, click on a different game object in game mode and activate that one, and back and forth, or have them all activated at one time. I know there must be a way to accomplish this. I'm fairly new to C# and I'm going nuts with this one. "Driving" objects around is no issue as there's a zillion ways to do it. I don't want to use collisions to perform this task, just simple mouse clicks.
void On$$anonymous$$ouseDown()
{
gameObject.SetActive(false);
}
Attach this to the gameobject you want to disable. Once disabled you cannot click it anymore though (obviously)
You might however just disable the mesh-renderer so the collider is still reacting to your clicks.
Thanks andzq! The reason I don't want to use colliders is that I don't wish to have the need to bump into them for deactivate / activate. $$anonymous$$ouse click is the preferred method if possible. Regarding your mention of disabling the mesh-renderer, will this have the same effect as the on$$anonymous$$ouseDown but still be reversible to activate the object again later on?
if you only disable the mesh renderer the gameobject and it's colliders/triggers will still be active and will respond to On$$anonymous$$ouseDown - yes.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095050im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cannot deactivate / activate gameobject, even in editor! 6 Answers
Is there any command that can reference deactivated objects? 1 Answer
Activate/deactivate all GameObjects with same tag c# 1 Answer
How do I enable and disable multiple game objects in Unity? 1 Answer
How to disable all objects but... 1 Answer