In a completely new project, with a game object in the hierarchy called "fred" this code works for me:
// c# example
using UnityEditor;
using UnityEngine;
public class Hider : MonoBehaviour {
[MenuItem ("MyMenu/Do Something")]
static void DoSomething () {
foreach (GameObject go in Selection.gameObjects) {
Debug.Log(go.name);
if (go.name == "fred") {
go.hideFlags = HideFlags.HideInHierarchy;
}
}
}
[MenuItem ("MyMenu/Do Something2")]
static void DoSomething2 () {
GameObject fred = GameObject.Find("fred");
if (fred) {
Debug.Log("found fred");
fred.hideFlags = HideFlags.None;
}
}
}
The first menu item looks at the selection and if it finds fred hides it. The second just makes sure it's visible.
↧