我有 Level scrollrect 但我喜欢当我去选择一个级别时我总是向我展示最后一个级别(如果我完成第 13 级解锁我第 14 级并且当转到菜单场景以在此之后显示我在中间的第 14 级如果我当我再次进入菜单场景以在中心显示第 15 级时完成第 14 级)可以做到这一点并保存最后一级的最后位置。当我打开菜单场景时,它会从底部向我显示 -图 1但我喜欢当我打开菜单场景以从该位置打开时,请参见 -图 2。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LevelData
{
public LevelData(string levelName)
{
string data = PlayerPrefs.GetString(levelName);
if (data == "")
return;
string[] allData = data.Split('&');
BestTime = float.Parse(allData[0]);
SilverTime = float.Parse(allData[1]);
GoldTime = float.Parse(allData[2]);
}
public float BestTime { set; get; }
public float GoldTime { set; get; }
public float SilverTime { set; get; }
public float BronzeTime { set; get; }
}
public class Menu : MonoBehaviour
{
private static Menu instance;
public static Menu Instance { get { return instance; } }
private int idLevel;
public Text timeText;
public Text txtselectLevel;
public string[] Level;
public ScrollRect scrol;
public GameObject PlayPanel;
public GameObject star1;
public GameObject star2;
public GameObject star3;
void Start()
{
instance = this;
PlayPanel.SetActive(false);
GameManager.Instance.Load();
idLevel = 0;
txtselectLevel.text = Level[idLevel];
PlayerPrefs.GetString(idLevel.ToString());
star1.SetActive(false);
star2.SetActive(false);
star3.SetActive(false);
}
public void Scenes()
{
SceneManager.LoadScene("L" + idLevel.ToString());
}
public void SelectLevel(int i)
{
idLevel = i;
PlayerPrefs.SetInt("idLevel", idLevel);
txtselectLevel.text = Level[idLevel];
LevelData level = new LevelData(i.ToString());
string minutes = ((int)level.BestTime / 60).ToString("00");
string seconds = (level.BestTime % 60).ToString("00.00");
timeText.text = (level.BestTime != 0.0f)
? "Best Time: " + minutes + ":" + seconds
: "";
if (level.BestTime < level.GoldTime)
{
star1.SetActive(true);
star2.SetActive(true);
star3.SetActive(true);
}
else if (level.BestTime < level.SilverTime)
{
star1.SetActive(true);
star2.SetActive(true);
star3.SetActive(false);
}
else if(level.BestTime < level.BronzeTime)
{
star1.SetActive(true);
star2.SetActive(false);
star3.SetActive(false);
}
else
{
star1.SetActive(false);
star2.SetActive(false);
star3.SetActive(false);
}
PlayPanel.SetActive(true);
}
public void ExitPanel()
{
PlayPanel.SetActive(false);
}
}