I'm making a Balloon popping game, and I want to get a prize for some amount of score for example if you made a score of 10 you get a sticker or if you made a score of 20 you get a keyholder, and if you have score 0 you get a try again text so the problem is that when I finish the game it displays the try again text then when you open a different program (like going to a folder or anything outside of unity the text refresh and then I get the right text. I have tried using update, LateUpdate and FixedUpdate but nothing changes.
Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class CountDownTimer : MonoBehaviour
{
//public string levelToLoad;
public float timer = 60f;
public Text timerSeconds;
public GameObject panelWin, score, time, pausa;
public int _playerScore;
public Text premio;
// Use this for initialization
void Start ()
{
timerSeconds = GetComponent<Text>();
time.SetActive(true);
panelWin.SetActive(false);
Time.timeScale = 1;
}
// Update is called once per frame
void LateUpdate ()
{
timer -= Time.deltaTime;
timerSeconds.text = timer.ToString("f0");
if (timer <=0)
{
if (PlayerPrefs.HasKey("Points"))
{
_playerScore = PlayerPrefs.GetInt("Points");
if (_playerScore == 0)
{
premio.text = "Intenta de nuevo!";
}
else
{
if (_playerScore >= 1 && _playerScore <= 10)
{
premio.text = "Tu premio es: una calco Bebé a bordo";
}
else
{
if (_playerScore >= 11 && _playerScore <= 20)
{
premio.text = "Tu premio es: un llavero Huggies";
}
else
{
if (_playerScore >= 21 && _playerScore <= 30)
{
premio.text = "Tu premio es: un pack de toallitas";
}
else
{
if (_playerScore >= 31 && _playerScore <= 40)
{
premio.text = "Tu premio es: un pack de
pañales";
}
else
{
if (_playerScore >= 41 && _playerScore >= 50)
{
premio.text = "Tu premio es: un bolso
Huggies";
}
}
}
}
}
}
}
panelWin.SetActive(true);
score.SetActive(false);
//time.SetActive(false);
pausa.SetActive(false);
if (panelWin == true)
{
Time.timeScale = 0;
}
}
}
public void DoARestart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void Menu()
{
SceneManager.LoadScene("TitleScreen");
}
}
This is the GameController Script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameControllerScript : MonoBehaviour {
public Transform balloonPrefab;
public Text scoreDisplay;
public Text scoreDisplayWin;
public int _playerScore = 0;
//private int _multiplier = 1;
private float _timeSinceLastSpawn = 0.0f;
private float _timeToSpawn = 0.0f;
private List<Transform> _balloons;
private const int BALLOON_POOL = 30;
void Start () {
PlayerPrefs.SetInt("Points", 0);
_balloons = new List<Transform>();
for (int i = 0; i < BALLOON_POOL; i++) {
Transform balloon = Instantiate(balloonPrefab) as Transform;
balloon.parent = this.transform;
_balloons.Add(balloon);
}
SpawnBalloon();
GameStart();
}
/*void InitMultiplier() {
if (PlayerPrefs.HasKey("Multiplier")) {
_multiplier = Mathf.Max (1, PlayerPrefs.GetInt ("Multiplier"));
}
}*/
void InitPoints() {
if (PlayerPrefs.HasKey("Points"))
{
_playerScore = PlayerPrefs.GetInt("Points");
}
}
// Update is called once per frame
void Update () {
_timeSinceLastSpawn += Time.deltaTime;
if (_timeSinceLastSpawn >= _timeToSpawn)
{
SpawnBalloon();
}
}
void SpawnBalloon() {
_timeSinceLastSpawn = 0.0f;
_timeToSpawn = Random.Range (0.0f, 2.0f);
foreach (Transform b in _balloons) {
BalloonScript bs = b.GetComponent<BalloonScript>();
if (bs && !bs.isActive) {
bs.Activate();
break;
}
}
}
public void AddPoints(int points=1) {
_playerScore += points;
UpdateScoreDisplay();
}
public void GameOver() {
SavePoints();
SceneManager.LoadScene("TitleScreen");
}
void UpdateScoreDisplay() {
scoreDisplay.text = "Puntaje: " + _playerScore.ToString();// + "(x" +
_multiplier.ToString() + ")";
scoreDisplayWin.text = "Tu puntaje es: " + _playerScore.ToString();
}
public void GameStart() {
InitPoints();
//InitMultiplier();
UpdateScoreDisplay();
}
void OnApplicationPause() {
SavePoints();
}
void OnApplicationQuit() {
SavePoints();
}
void SavePoints() {
PlayerPrefs.SetInt("Points", _playerScore);
}
}
I dont have any errors on the console, would be very glad if anyone can help! Thanks!