В основном меню есть также кнопка сброса.
Проблема:
, если я нажму кнопку сброса сразу после возвращения в основной меню, все это работает, все уровни. Кнопка «Воспроизвести», чтобы открыть панель выбора уровня, а затем вернуться в главное меню и нажмите кнопку сброса, сброс больше не работает. Кажется, что данные уровня восстанавливаются или не удаляются должным образом. < /P>
Вот все мой скрипт; < /p>
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
Rigidbody2D rb;
private float horizontalInput;
private float speed = 20.0f;
private void Start()
{
rb = GetComponent();
}
private void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(horizontalInput * speed * 100 * Time.deltaTime, rb.velocity.y);
}
}
< /code>
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SelectLevels : MonoBehaviour
{
public Button[] buttons;
public Button[] worlds;
private int unlockedLevel;
private void Awake()
{
unlockedLevel = PlayerPrefs.GetInt("UnlockedLevel", 1);
for(int i = 0; i < buttons.Length; i++)
{
buttons[i].interactable = false;
}
for (int i = 0; i < unlockedLevel; i++)
{
buttons[i].interactable = true;
}
if(unlockedLevel > 3)
{
worlds[1].interactable = true;
}
else
{
worlds[1].interactable = false;
}
}
public void OpenLevel(int levelIndex)
{
SceneManager.LoadScene(levelIndex);
}
public void QuitGame()
{
Application.Quit();
Debug.Log("QUIT");
}
}
< /code>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class FinishPoint : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
UnlockLevel();
int currentLevel = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentLevel+1);
}
}
void UnlockLevel()
{
if (SceneManager.GetActiveScene().buildIndex >= PlayerPrefs.GetInt("UnlockedLevel"))
{
PlayerPrefs.SetInt("UnlockedLevel", SceneManager.GetActiveScene().buildIndex + 1);
PlayerPrefs.Save();
}
}
public void GoToHome(int levelIndex)
{
SceneManager.LoadScene(levelIndex);
}
}
< /code>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResetGame : MonoBehaviour
{
public void RestartGame()
{
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
}
}
< /code>
What I’ve checked:
ResetGame()Нет Playerprefs.setint (...) в функции сброса.
Может быть, панель или какой -либо другой сценарий переписывает данные после повторного снятия? Есть идеи, что может вызвать это?
Подробнее здесь: https://stackoverflow.com/questions/796 ... game-issue