Unity active、enabled

1. GameObject.activeSelf:

返回该GameObject的本地活动状态,该状态是使用GameObject.SetActive设置的。
GameObject可能处于非活动状态,因为父级处于非活动状态,即使该状态返回true也是如此。所有父母均处于活动状态后,将使用此状态。如果要检查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");
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容