Untitled
plain_text
a month ago
5.6 kB
0
Indexable
Never
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class UIManager : MonoBehaviour { public GameObject pauseMenu; public GameObject ingameMenu; public DriftManager driftManager; // Update is called once per frame void Update() { } public void OpenPauseMenu() { // Check if singleplayer or host game Time.timeScale = 0f; pauseMenu.SetActive(true); ingameMenu.SetActive(false); } public void Resume() { pauseMenu.SetActive(false); ingameMenu.SetActive(true); Time.timeScale = 1f; // other code } public void RestartLevel() { int currentSceneindex = SceneManager.GetActiveScene().buildIndex; SceneManager.LoadScene(currentSceneindex); pauseMenu.SetActive(false); driftManager.totalScore = 0; Time.timeScale = 1f; } public void EndRun() { //Fa Activ Obiectul in Scena cu meniul driftManager.totalScoreTransfer += driftManager.totalScore; PlayerPrefs.SetFloat("TotalScore", driftManager.totalScoreTransfer); SceneManager.LoadScene("MenuScene"); } } -------------------SCENE 1 (game) using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using System.Threading.Tasks; public class DriftManager : MonoBehaviour { public Rigidbody playerRB; public TMP_Text totalScoreText; public TMP_Text currentScoreText; public TMP_Text factorText; public TMP_Text driftAngleText; private float speed = 0; private float driftAngle = 0; private float driftFactor = 1; public float currentScore; //ITS HERE isee public float totalScore; public float totalScoreTransfer; public bool isDrifting = false; public float scoreAdd; public float minimumSpeed = 5; public float minimumAngle = 10; public float driftingDelay = 0.5f; public float maxFactor; public GameObject driftingObject; public Color normalDriftColor; public Color nearStopColor; public Color driftEndedColor; private IEnumerator stopDriftingCoroutine = null; // Start is called before the first frame update void Start() { driftingObject.SetActive(false); } // Update is called once per frame void Update() { totalScoreTransfer = totalScore; if(driftFactor >= maxFactor) { driftFactor = maxFactor; } ManageDrift(); ManageUI(); } void ManageDrift() { speed = playerRB.velocity.magnitude; driftAngle = Vector3.Angle(playerRB.transform.forward, (playerRB.velocity + playerRB.transform.forward).normalized); if (driftAngle > 120) { driftAngle = 0; } if (driftAngle >= minimumAngle && speed > minimumSpeed) { if (!isDrifting || stopDriftingCoroutine != null) { StartDrift(); } } else { if (isDrifting && stopDriftingCoroutine == null) { StopDrift(); } } if (isDrifting) { currentScore += Time.deltaTime * driftAngle * driftFactor * scoreAdd; driftFactor += Time.deltaTime; driftingObject.SetActive(true); } } async void StartDrift() { if (!isDrifting) { await Task.Delay(Mathf.RoundToInt(1000 * driftingDelay)); driftFactor = 1; } if (stopDriftingCoroutine != null) { StopCoroutine(stopDriftingCoroutine); stopDriftingCoroutine = null; } currentScoreText.color = normalDriftColor; isDrifting = true; } void StopDrift() { stopDriftingCoroutine = StoppingDrift(); StartCoroutine(stopDriftingCoroutine); } private IEnumerator StoppingDrift() { yield return new WaitForSeconds(0.5f); currentScoreText.color = nearStopColor; yield return new WaitForSeconds(driftingDelay * 4f); totalScore += currentScore; isDrifting = false; currentScoreText.color = driftEndedColor; yield return new WaitForSeconds(0.5f); currentScore = 0; driftingObject.SetActive(false); } void ManageUI() { totalScoreText.text = " Total: " + (totalScore).ToString("###,###,000"); factorText.text = driftFactor.ToString("###,###,##0.0") + "X"; currentScoreText.text = currentScore.ToString("###,###,000"); driftAngleText.text = driftAngle.ToString("###,##0") + "°"; } } -------- scene 1 (game) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class PlayerInformationSaver : MonoBehaviour { public DriftManager driftManager; public GameObject WindowDriftPoints; private float driftPoints; private float getScore; [Header("Text")] [field: SerializeField] public TMP_Text driftPointsText; public TMP_Text driftpointsConverted; public TMP_Text driftScoreText; private void Start() { getScore = PlayerPrefs.GetFloat("TotalScore", 0f); driftPoints += getScore; } private void Update() { driftPointsText.text = "DP: " + (int)driftPoints; } } ------- Scene 0 (menu) `