Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ScoreManager : MonoBehaviour
- {
- public static int score;
- Text text;
- // Start is called before the first frame update
- void Start()
- {
- text = GetComponent<Text>();
- //score = 0;
- score = PlayerPrefs.GetInt("PlayerCurrentScore");
- }
- // Update is called once per frame
- void Update()
- {
- if (score < 0)
- score =0;
- text.text = "" + score;
- }
- public static void AddPoints(int pointsToAdd)
- {
- score += pointsToAdd; // Add points to the score
- PlayerPrefs.SetInt("PlayerCurrentScore", score); // Save the score in the PlayerPrefs to next level
- }
- public static void Reset()
- {
- score = 0;
- PlayerPrefs.SetInt("PlayerCurrentScore", score); // Save the score in the PlayerPrefs to next level incase loss of points
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement