Unity3D中的C#腳本環境(在Mono下運行)在銷燬對象時具有很好的行爲。所有指向該銷燬的對象引用獲得全自動空:C#自動引用分配 - 正在引用null
GameObject ref1 = (GameObject)Instantiate(obj);
GameObject ref2 = ref1;
if (ref1 != null)
Debug.Log("ref1 is not null");
DestroyImmediate(ref1);
if (ref1 == null)
Debug.Log("ref1 is null");
if (ref2 == null)
Debug.Log("ref2 is null");
輸出:
ref1 is not null
ref1 is null
ref2 is null
如何達致這任何想法?
感謝
只要找出如果ref1和ref2不是一個遊戲對象,而是一個System.Object,那麼它不會工作。 – noon 2010-01-24 21:42:20