Not sure if that was the right wording for this question but hopefully you guys understand. I’m trying to save my score value in game so that I can display it on the death screen. Thanks in advance!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
int scriptScore = 0;
public Text score;
int timeUntil = 5;
public static int Otherscore;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (PlayerDeath.isAlive == true)
{
score.text = "Score: " + scriptScore;
timeUntil--;
}
if(timeUntil == 0)
{
scriptScore++;
timeUntil = 5;
}
Otherscore = scriptScore;
}
}
That’s the script for the score in game. And below is my attempt at displaying it on the death screen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class HighScore : MonoBehaviour
{
public TextMeshProUGUI highScore;
void Start()
{
highScore.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
public void displayScore()
{
if(Score.Otherscore > PlayerPrefs.GetInt("HighScore", 0))
{
PlayerPrefs.SetInt("HighScore", Score.Otherscore);
highScore.text = Score.Otherscore.ToString();
}
}
}