I am trying to take the score from my gameplay scene and display it on my end screen. I am not sure why the"PlayerPrefs" isn't working. I have the code for the score and the code for the score to be displayed at the end screen below. Thanks in advance.
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class score : MonoBehaviour
{
public TMP_Text output;
public float count = 0.0f;
public float speed = 0.001f;
// Start is called before the first frame update
void Start()
{
output.text = "Testing...123";
}
// Update is called once per frame
void Update()
{
count = count + 2*speed;
//cast (int) of a float (1234).0987
int number = (int)count;
Debug.Log(count);
//Convert number to a string repreentation of its values
output.text = "Score: " + number.ToString();
int score = PlayerPrefs.GetInt("count");
Debug.Log("Score: " + score);
}
}
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class finalScore : MonoBehaviour
{
public TMP_Text finalScoreText;
void Start()
{
// Get the score from the previous scene
int score = PlayerPrefs.GetInt("count");
// Update the score text component
finalScoreText.text = "Final Score: " + score.ToString();
}
}