Version: 2020.1

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"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961