Skip to content

Instantly share code, notes, and snippets.

@romainPechot
Created April 21, 2015 12:53
Show Gist options
  • Save romainPechot/80baca0ecde766a12526 to your computer and use it in GitHub Desktop.
Save romainPechot/80baca0ecde766a12526 to your computer and use it in GitHub Desktop.
An Unity editor tool shortcut to quickly de-activate the gameObject(s) selected.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class SetActiveGameObject : Editor
{
[MenuItem("Tools/On-Off GameObject %g")]
private static void EnableDisableGameObject()
{
// fetch
GameObject[] _aGO = Selection.gameObjects;
// save undo
Undo.RecordObjects(_aGO, "de-activate gameObject(s)");
// switch state
for(int i = 0; i < _aGO.Length; i++) _aGO[i].SetActive(!_aGO[i].activeSelf);
}// EnableDisableGameObject
}// SetActiveGameObject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment