1. GameObject.activeSelf:
返回該GameObject的本地活動狀態(tài)莫其,該狀態(tài)是使用GameObject.SetActive設(shè)置的注服。
GameObject可能處于非活動狀態(tài),因為父級處于非活動狀態(tài)澎埠,即使該狀態(tài)返回true也是如此虽缕。所有父母均處于活動狀態(tài)后,將使用此狀態(tài)蒲稳。如果要檢查GameObject是否在場景中實際上被視為活動對象氮趋,請使用 GameObject.activeInHierarchy
2. Behaviour.isActiveAndEnabled:
GameObject可以是active或者not active伍派,同樣,script可以是enabled或者disabled剩胁,如果GameObject是active并且有一個enabled script诉植,那么isActiveAndEnabled返回true。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public Image pauseMenu;
public void Update()
{
//Checks if the object is enabled.
if (pauseMenu.isActiveAndEnabled)
{
//If the image is enabled, print "Enabled" in the console. (Stops when the image is disabled).
Debug.Log("Enabled");
}
}
}