运用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已经激活");
}
}
}
代码运行效果如下: