问题描述
我不知道从哪里开始或如何搜索有关此主题的更多信息,所以我来这里寻求建议。我想制作一个 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 (将#修改为@)