My Game Score disappears completely after the next level

So I coded where i could show the amount of lives the user has during the game. However now I am running into an issue where while the lives show for each level, the amount of points the player has disappears for the next level.
I know it has to do with my code but I have spent 2 hours trying to figure it out. If someone can help me spot the error, I feel like it is destroying the string after the next level
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using TMPro;
using System;

public class GameStatus : MonoBehaviour
{
public static GameStatus instance;
public static int fireForLevelDown;
[Range(0.1f, 10f)] [SerializeField] float gameSpeed = 1f;
[SerializeField] int currentScore = 0;
[SerializeField] int pointsPerBlockDestroyed = 83;
[SerializeField] TextMeshProUGUI scoreText;
[SerializeField] bool isAutoPlayEnabled;

[SerializeField]  TextMeshProUGUI lifeCount;
// Start is called before the first frame update
void Awake()
{
    MakeInstance();
    int gameStatusCount = FindObjectsOfType<GameStatus>().Length;
    if (gameStatusCount > 1)
    {
        gameObject.SetActive(false);
        Destroy(gameObject);

    }
    else
    {
        DontDestroyOnLoad(gameObject);
    }
}

void MakeInstance()
{
   if(instance ==null)
    {
        instance = this;
        Debug.Log("Make Instance");
    }
}
public void CountLives(int numOfLives)
{
    Debug.Log("Number of Lives" + numOfLives);
  lifeCount.text = "Lives" + numOfLives.ToString();
}
public void CountFire(int numFire)
{
    numFire = 1;
    LoseCollider.numOfLives--;
    numFire = fireForLevelDown;
    CountLives(LoseCollider.numOfLives);
   
}


private void Start()
{
    scoreText.text = currentScore.ToString();
}
// Update is called once per frame
void Update()
{
    Time.timeScale = gameSpeed;
    
}

public void AddtoScore()
{
    currentScore += pointsPerBlockDestroyed;
    scoreText.text = currentScore.ToString();
}
public void ResetGame()
{
    Destroy(gameObject);
}
public bool IsAutoPlayEnabled()
{
    return isAutoPlayEnabled;
}

}

what is the error message you recieve

no error, my game runs. but when it goes to the next level the scoretext seems to destroy itself

actually i have no idea why since I havent changed anything, but it is showing. but when it laods to next level bboth text have this white-grey cast over them until i click for the rocket to start

Hi,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe ResetGame gets called and destroys your GameStatus object. That might explain why the points get lost when a new scene gets loaded.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms