Version: 2017.3

GameObject.activeInHierarchy

매뉴얼로 전환
public bool activeInHierarchy ;

설명

Is the GameObject active in the scene?

This lets you know if a gameObject is active in the game. That is the case if its GameObject.activeSelf property is enabled, as well as that of all it's parents.

//This script shows how the activeInHierarchy state changes depending on the active state of the GameObject’s parent

using UnityEngine;

public class ActiveInHierarchyExample : MonoBehaviour { //Attach these in the Inspector public GameObject m_ParentObject, m_ChildObject; //Use this for getting the toggle data bool m_Activate;

void Start() { //Deactivate parent GameObject and toggle m_Activate = false; }

void Update() { //Activate the GameObject you attach depending on the toggle output m_ParentObject.SetActive(m_Activate); }

void OnGUI() { //Switch this toggle to activate and deactivate the parent GameObject m_Activate = GUI.Toggle(new Rect(10, 10, 100, 30), m_Activate, "Activate Parent GameObject");

if (GUI.changed) { //Output the status of the GameObject's active state in the console Debug.Log("Child GameObject Active : " + m_ChildObject.activeInHierarchy); } } }

Unlike GameObject.activeSelf, this also checks if any parent GameObjects affect the GameObject’s currently active state.

When a parent GameObject is deactivated, its children are usually marked as active even though they are not visible, so they are still active according to GameObject.activeSelf. However, GameObject.activeInHierarchy ensures this doesn’t happen by instead checking that the GameObject hasn’t been deactivated by a member in its hierarchy.

//This script shows how activeInHierarchy differs from activeSelf. Use the toggle  to alter the parent and child