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;
}
}