Fixed score reset and highscore check

This commit is contained in:
Michał Gdula 2022-05-15 12:15:06 +01:00
parent 1a641f3c6f
commit ed68280480
4 changed files with 21 additions and 8 deletions

View file

@ -10,7 +10,6 @@ public class endTrigger : MonoBehaviour
if (other.gameObject.CompareTag("Player"))
{
SceneManager.LoadScene("end");
SceneManager.UnloadSceneAsync("game");
}
}
}

View file

@ -6,18 +6,16 @@ using TMPro;
public class highScoreCheck : MonoBehaviour
{
TextMeshProUGUI textBox;
public float highScore = 0;
public float lowestTime;
void Start()
{
highScore = PlayerPrefs.GetFloat("highScore");
if (highScore > PlayerPrefs.GetFloat("timeScore"))
if (PlayerPrefs.GetFloat("lowestTime") > PlayerPrefs.GetFloat("timeScore"))
{
PlayerPrefs.SetFloat("highScore",PlayerPrefs.GetFloat("timeScore"));
highScore = PlayerPrefs.GetFloat("timeScore");
PlayerPrefs.SetFloat("lowestTime",PlayerPrefs.GetFloat("timeScore"));
}
textBox = GetComponent<TextMeshProUGUI>();
textBox.SetText("Shortest Time: {0}s", highScore);
textBox.SetText("Shortest Time: {0}s", PlayerPrefs.GetFloat("lowestTime"));
}
}

View file

@ -7,6 +7,10 @@ public class levelLoader : MonoBehaviour
{
public void NextLevel()
{
if (SceneManager.GetActiveScene().name == "menu")
{
PlayerPrefs.SetFloat("lowestTime",9999f);
}
SceneManager.LoadScene("game");
}
}

12
scoreReset.cs Normal file
View file

@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class scoreReset : MonoBehaviour
{
public void SendBack()
{
SceneManager.LoadScene("menu");
}
}