如何统一传递对象的销毁状态 [英] how to pass the destroyed state of an object in unity

查看:78
本文介绍了如何统一传递对象的销毁状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的销毁游戏对象可以在我的游戏中使用,但是每当我更改场景然后返回到销毁该对象的场景时,它就会再次存在.我如何使它保持销毁状态?我需要反序列化吗?我不需要它来创建一个保存文件.我只需要被破坏的物体不再出现.

my destroy game object works in my game but whenever I change scenes then return back to the scene where I destroyed the object, it is there again. how do i make it stay destroyed? do i have to deserialize it? i don't need it to creat a save file. i just need the destroyed object to not appear again.

void OnMouseDown()
{
     i.AddItem(0);
     nameobj = gameObject.name;
     Destroy(gameObject);
}

推荐答案

public static class DestroyedObjects 
{ 
    static List<GameObject> objs = new List<GameObject>();
    public static void Add(GameObject obj) 
    {
        if(!objs.Contains(obj))
            objs.Add(obj); 
    } 
}

并像这样使用它:

void OnMouseDown()
{
    i.AddItem(0);
    nameobj = gameObject.name;
    DestroyedObjects.Add(gameObject);
    // Destroy(gameObject);
    gameObject.SetActive(false);
}

这篇关于如何统一传递对象的销毁状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆