Hi i am working on a project i have many scripts for coins the follwoing are the scripts
Here is the gameovermanager script i use it that i am using it in the winning scene and the game over scene where all of the coins show that how many you have collected
using UnityEngine;
using UnityEngine.UI;
public class GameOverManager : MonoBehaviour
{
public Text totalCoinsText;
public Text totalApplesText;
public Text totalOrangesText;
public Text totalGrapesText;
public Text totalBananasText;
void Start()
{
totalCoinsText.text = "Total Coins: " + LevelManager.totalCoins;
totalApplesText.text = "Total Apples: " + LevelManager.totalApples;
totalBananasText.text = "Total Bananas: " + LevelManager.totalBananas;
totalGrapesText.text = "Total Grapes: " + LevelManager.totalGrapes;
totalOrangesText.text = "Total Oranges: " + LevelManager.totalOranges;
}
}
and the following is the gamemanager script that is i have given in everyscene i mean that in levels and also in the gameover scene
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
public int totalCoins;
public int totalApples;
public int totalOranges;
public int totalGrapes;
public int totalBananas;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
}
And the following is the levelmanger script
using UnityEngine;
using UnityEngine.SceneManagement;
public static class LevelManager
{
public static string currentLevel;
public static int totalCoins;
public static int totalApples;
public static int totalGrapes;
public static int totalOranges;
public static int totalBananas;
public static void LoadLevel(string levelName)
{
currentLevel = levelName;
//totalCoins = 0;
SceneManager.LoadScene(levelName);
}
public static void ReloadCurrentLevel()
{
SceneManager.LoadScene(currentLevel);
}
public static void GameOver()
{
SceneManager.LoadScene("GameOver");
}
}
so how can i add the coins to the mainmenu that all of the coins save there and also if i will stop the game then they have to be saved