运用gameObject.activeSelf对SetActive(bool value)进行条件判断

运用gameObject.activeSelf对SetActive(bool value)进行条件判断

using UnityEngine;
using UnityEngine.UI;
public class ActiveSelfTest : MonoBehaviour {
    public GameObject ImageBG;
    public Button button;

	void Start () {
        ImageBG.SetActive(false);
        button.onClick.AddListener(OpenImageBG);
	}

    private void OpenImageBG()
    {
        ImageBG.SetActive(true);
        if (ImageBG.activeSelf)
        {
            Debug.Log("OpenImageBG已经激活");
        }
    }
}

代码运行效果如下:
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43492764/article/details/85685997