From 015cefe9b79c5ab39dc4c651fb649b2940d0f64f Mon Sep 17 00:00:00 2001 From: nexovec Date: Sat, 29 Jan 2022 22:45:27 +0100 Subject: [PATCH] fixed maxDistanceFromCenterLine --- Assets/Scripts/PlayerController.cs | 3 +-- Assets/Scripts/UiController.cs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 1eaf314..1c77170 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -4,7 +4,7 @@ using UnityEngine; public class PlayerController : MonoBehaviour { - public float maxDistanceFromCenterLine; + public float maxDistanceFromCenterLine = 30.0f; [Header("Move")] public float speed = 7.5f; public float maxSpeed = 15.0f; @@ -167,7 +167,6 @@ public class PlayerController : MonoBehaviour Debug.Log("Player fell out of map."); rb.velocity = Vector3.zero; Physics.gravity = -Vector3.up * 9.81f; - UnityEngine.SceneManagement.SceneManager.LoadScene(0); } } diff --git a/Assets/Scripts/UiController.cs b/Assets/Scripts/UiController.cs index 5634f57..8b9e427 100644 --- a/Assets/Scripts/UiController.cs +++ b/Assets/Scripts/UiController.cs @@ -8,6 +8,7 @@ public class UiController : MonoBehaviour public GameObject player = null; private float startPosition; public TextMeshProUGUI uiDistance; + public int highScore; public float distance = 0.0f; private float oldDistance = 0.0f; @@ -17,6 +18,27 @@ public class UiController : MonoBehaviour startPosition = this.player.transform.position.z; Cursor.lockState = CursorLockMode.None; Cursor.visible = true; + + PlayerController.LoadSave(); + } + static void SaveGame() + { + PlayerPrefs.SetInt(PlayerController.highScore); + PlayerPrefs.Save(); + Debug.Log("Game data saved!"); + } + void LoadGame() + { + if (PlayerPrefs.HasKey("HighestScore")) + { + this.highScore = PlayerPrefs.GetInt("SavedInteger"); + Debug.Log("Game data loaded!"); + } + else + { + this.highScore = 0; + } + } // Update is called once per frame