I have a little problem with my game (again).
In my game your collecting coins.
This is the coinCollect script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CollectCoins : MonoBehaviour {
public Text CoinText;
public static int CoinCount = 0;
public Deathmenu deathMenu;
// Use this for initialization
void Start ()
{
CoinCount = PlayerPrefs.GetInt ("TotalCoins");
}
// Update is called once per frame
void Update () {
CoinText.text = ((int)CoinCount).ToString();
}
public void SaveCoins()
{
PlayerPrefs.SetFloat ("TotalCoins", CoinCount);
}
public void OnDeath()
{
SaveCoins();
deathMenu.ToggleEndMenu(CoinCount);
}
}
So im saving the coins on the Deathmenu and that works and its also saving on the MainMenu,
But If i restart the game the TotalCoins on the MainMenu are loaded So you start the game and all the coins randomly disappear.
//Main Menu Script
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using UnityEngine;
public class MainMenu : MonoBehaviour {
public Text TotalCoinsText;
// Use this for initialization
void Start ()
{
TotalCoinsText.text = "" + (int)PlayerPrefs.GetFloat ("TotalCoins");
}
public void ToGame ()
{
SceneManager.LoadScene ("test");
}
}
I want to load the coins from teh main menu in the game so you can collect more.