gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
using System.Collections; using System.Collections.Generic; using UnityEngine; using…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //This line enables use of uGUI classes like Text.
public class ScoreCounter : MonoBehaviour { //[Header("Dynamic")] public static int SCORE { get; set; }
codeprivate Text uiText; private void Start() { uiText = GetComponent<Text>(); LoadScore(); } private void Update() { uiText.text = SCORE.ToString("Score:#,0"); //This 0 is a zero! } public void AddScore(int scoreAmount) { SCORE += scoreAmount; SaveScore(); } public void ResetScore() { SCORE = 0; SaveScore(); } private void SaveScore() { PlayerPrefs.SetInt("Score", SCORE); } private void LoadScore() { SCORE = PlayerPrefs.GetInt("Score", 0); }} make it so if the "Win" scene changes to "Level1" scene (sceneIndex 3 to sceneIndex 0) then the ResetScore() method is called
- Assistant
To achieve this, you can use the SceneManager.LoadScene method and handle the scene change in your ScoreCounter script. Here's an updated version of your script that includes the desired functionality:
csharp