C# 如何使按钮在统一中脱色?

C# 如何使按钮在统一中脱色?,c#,android,visual-studio,unity3d,button,C#,Android,Visual Studio,Unity3d,Button,我怎么能让红色按钮“开始新游戏”消失,当一些东西被保存在预制 using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.SceneManagement; public class Savescene : MonoBehaviour { public void save() { if (!File.

我怎么能让红色按钮“开始新游戏”消失,当一些东西被保存在预制

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Savescene : MonoBehaviour
{
   public void save()
    {
        if (!File.Exists("saved.txt"))
        {
            File.Create("saved.txt");
        }
        else
        {
        StreamWriter sw = new StreamWriter("saved.txt");
        sw.WriteLine("True");
        sw.Close();
        }
        PlayerPrefs.SetInt("SceneSaved", SceneManager.GetActiveScene().buildIndex);
    }

    public void Load()
    {
        SceneManager.LoadScene(PlayerPrefs.GetInt("SceneSaved"));
    }
}
钮扣

相关代码


因为英语不是我的母语,所以我无法完全理解这句话:
当你的问题中有东西通过预制件保存时。但据我所知,当游戏已经开始时,你们需要让按钮消失吗?您可以在PlayerPrefs中写入一些信息,如下所示:
PlayerPrefs.SetInt(“showStartNewGameButton”、-1)//或除0以外的任何其他数字
然后您可以检查,如果“showStartNewGameButton”等于0(默认值),则必须显示按钮,否则不显示

可以通过以下方式停用对象来实现消失本身:
button.gameObject.SetActive(false);//如果你想显示按钮,你必须是真的,而不是假的

没有附件。我已经添加了带有链接的图片感谢快速回复感谢编辑(我英语不好)@Lomusire yes^^^但是对于你的问题:一般来说,不要发布代码的图片!请将您的代码复制粘贴到问题中,并通过
{}
按钮格式化。然后通常使用
someGameObject.SetActive(true)来“禁用”东西
以便您可以读取
PlayerPrefs
并在按钮不是默认值时禁用该按钮,例如
var scene=PlayerPrefs.GetInt(“SceneSaved”,-1);button.gameObject.SetActive(场景==-1)