Behaviour.isActiveAndEnabled

切换到手册
public bool isActiveAndEnabled ;

描述

是否已激活并启用 Behaviour?

游戏对象可以是激活或非激活状态。同样,可以启用或禁用脚本。如果游戏对象处于激活状态且具有启用的脚本,则 isActiveAndEnabled 将返回 /true/。否则,返回 /false/。

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"); } } }