What I am trying to do is collect coins in my main scene and then when I switch to my “safeRoom” scene the coins subtract from my main coin int and add to my new coinPile int that is saved in playerprefs. Kind of like taking the money in your pocket and putting it in a bank.
I’m using DontDestroyOnLoad to keep the collected coins when entering a new scene and then added this code to my GUI to make the coins move to the new int…
#pragma strict
var CoinPile : int;
var coinCount : GUIText;
function Start () {
CoinPile = PlayerPrefs.GetInt("coinsCounted");
}
function Update () {
if (PlayerPrefs.GetInt("coinsCounted")<CoinPile)
{
PlayerPrefs.SetInt("coinsCounted", CoinPile);
}
}
function OnGUI ()
{
coinCount.text = "Coins Collected: " + CoinPile;
}
but obviously I’m doing it wrong. Can anyone help?