小编mke*_*man的帖子

在销毁GameObjects时我应该取消字段吗?

如果通过Inspector设置了一个字段,我应该在销毁GameObject时使其无效吗?Unity会自动执行此操作吗?

public class TestClass : MonoBehaviour
{
    public Image Icon;
    public Button CloseButton;

    private void Start()
    {
        Icon.color = Color.black;
        CloseButton.onClick.AddListener( MyButtonListener );
    }

    private void OnDestroy()
    {
        CloseButton.onClick.RemoveListener( MyButtonListener );

        //DO I NEED THIS?
        Icon = null;
        CloseButton = null;
    }

    private void MyButtonListener() { }
}
Run Code Online (Sandbox Code Playgroud)

c# memory-management unity-game-engine

1
推荐指数
1
解决办法
69
查看次数

标签 统计

c# ×1

memory-management ×1

unity-game-engine ×1