验证方法
将下方脚本挂在2个对象上,勾选填充相关的值,运行看输出
验证代码
using System.Collections.Generic;
using UnityEngine;
namespace DC
{
/// <summary>
/// 验证destroy game object之后留存在上面的component是否为null
/// </summary>
public class DestroyAndInstance : MonoBehaviour
{
public bool mDestroy;
public float mDelay;
public DestroyAndInstance mOther;
public GameObject mOtherGameObject;
private List<DestroyAndInstance> mList;
void Start()
{
if (mDestroy)
{
Invoke("DestroySelf", mDelay);
}
else
{
CheckResult();
mList = new List<DestroyAndInstance>();
mList.Add(mOther);
Invoke("CheckResult", mDelay);
}
}
public void CheckResult()
{
Debug.Log(mOtherGameObject == null);
Debug.Log(mOther == null);
if (null != mList)
{
Debug.Log(mList[0]);
}
if (null != mOther)
{
Debug.Log(mOther.SomeValue());
}
}
public void DestroySelf()
{
Destroy(gameObject);
}
public bool SomeValue()
{
return false;
}
}
}