微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何统一制作保存/收藏夹系统?

如何解决如何统一制作保存/收藏夹系统?

我不知道从哪里开始或如何搜索有关此主题的更多信息,所以我来这里寻求建议。我想制作一个 Saved 系统,玩家可以在其中按下按钮并让对象出现在收藏夹列表中(将您带到游戏场景的按钮列表)。

我已经成功了

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class CustomSave : MonoBehavIoUr
{
    public Button Custom;
    public Button Save;
    public Button Save1;

    public void CustomSaved()
    {
        PlayerPrefs.SetInt("CustomSaved",PlayerPrefs.GetInt("CustomSaved") +1);

        if (PlayerPrefs.GetInt("CustomSaved") % 2 != 0)
        {
            var colors0 = Save.GetComponent<Button>().colors;
            colors0.normalColor = Color.red;
            Save.GetComponent<Button>().colors = colors0;
            
            var colors1 = Save1.GetComponent<Button>().colors;
            colors1.normalColor = Color.red;
            Save1.GetComponent<Button>().colors = colors1;
                     

            PlayerPrefs.SetInt("NumberOfSaved",PlayerPrefs.GetInt("NumberOfSaved") + 1);

        }
        if (PlayerPrefs.GetInt("CustomSaved") % 2 == 0 && PlayerPrefs.GetInt("CustomSaved") !=0)
        {
            var colors = Save.GetComponent<Button>().colors;
            colors.normalColor = Color.white;
            Save.GetComponent<Button>().colors = colors;

            var colors2 = Save1.GetComponent<Button>().colors;
            colors2.normalColor = Color.white;
            Save1.GetComponent<Button>().colors = colors2;

            PlayerPrefs.SetInt("NumberOfSaved",PlayerPrefs.GetInt("NumberOfSaved") - 1);
        }


        if (PlayerPrefs.GetInt("NumberOfSaved") == 0)
        {
            Debug.Log("Mamamia");
            RectTransform rt = Custom.GetComponent<RectTransform>();
            rt.anchoredPosition = new Vector2(-2000,700);
        }
        if (PlayerPrefs.GetInt("NumberOfSaved") == 1)
        {
            RectTransform rt = Custom.GetComponent<RectTransform>();
            rt.anchoredPosition = new Vector2(-285,435);
        }
        if (PlayerPrefs.GetInt("NumberOfSaved") == 2)
        {

            RectTransform rt = Custom.GetComponent<RectTransform>();
            rt.anchoredPosition = new Vector2(245,435);
        }
    }
}

不幸的是,这不会移动自定义按钮。 如果我将最后 3 个 if() 放在 void Update() 函数中,则每当具有此脚本的改编变体的 2 个对象处于活动状态时,它们都会进入第二个空间。有没有更简单的方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。