Добавлен максимальный счёт с сохранением

This commit is contained in:
2025-01-31 14:44:57 +03:00
parent 64d5577fd8
commit 3f13aa2da6
6 changed files with 201 additions and 64 deletions

View File

@ -1,7 +1,6 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.XR.Interaction.Toolkit;
using static UnityEngine.XR.OpenXR.Features.Interactions.DPadInteraction;
public class HitDetectorScript : MonoBehaviour
{
@ -23,13 +22,20 @@ public class HitDetectorScript : MonoBehaviour
[SerializeField] XRBaseController _LeftController;
[SerializeField] XRBaseController _RightController;
[HideInInspector]
public UnityEvent Dead = new UnityEvent();
[SerializeField] private ScoreManagerScript _ScoreManager;
private void OnTriggerEnter(Collider other)
{
//Debug.Log(other.gameObject.name);
if (other.gameObject.CompareTag("Car") && !_IsDead)
{
if (PlayerPrefs.GetInt("Best score") < _ScoreManager.CurrentScore)
{
PlayerPrefs.SetInt("Best score", _ScoreManager.CurrentScore);
}
_IsDead = true;
Dead.Invoke();
@ -40,7 +46,7 @@ public class HitDetectorScript : MonoBehaviour
UISpawn();
TriggerHaptic(_LeftController);
TriggerHaptic (_RightController);
TriggerHaptic(_RightController);
Debug.Log("Player was hitted car");
//SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);

View File

@ -1,10 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MenuScript : MonoBehaviour
{
[SerializeField] private int _BestScore;
[SerializeField] private TextMeshProUGUI _TextScore;
private void OnEnable()
{
_BestScore = PlayerPrefs.GetInt("Best score");
_TextScore.text = "Лучший счёт - " + _BestScore;
}
// Start is called before the first frame update
public void RestartGame()
{

View File

@ -18,6 +18,11 @@ public class ScoreManagerScript : MonoBehaviour
private int _CurrentScore = 0;
public int CurrentScore
{
get { return _CurrentScore; }
}
[SerializeField]
private TextMeshPro _ScoreText;