- Home /
IAP button fails to update GUI after scene change
Hi there, I am having an issue with making purchases to the Google Play Store (fake store) on the scene in Unity. When I load the scene on Play, the IAP buttons are active and show a debug log of purchase complete and adding coins to my coins counter. When the button is pushed and purchased, my coins counter updates with the amount purchased.
When, I change scenes to the game from the menu scene and go back to the menu scene, the IAP buttons no longer update my coins counter when purchased. The debug log still says that the purchase was complete and coins were added.
using UnityEngine;
using System;
using System.Collections;
public class CoinManager : MonoBehaviour
{
public static CoinManager Instance;
public int Coins { get; private set; }
public static event Action<int> CoinsUpdated = delegate {};
[SerializeField]
int INITIAL_COINS = 100;
const string COINS = "COINS"; // key name to store high score in PlayerPrefs
void Awake()
{
if (Instance)
{
DestroyImmediate(gameObject);
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
Reset();
}
public void Reset()
{
// Initialize coins
Coins = PlayerPrefs.GetInt(COINS, INITIAL_COINS);
Debug.Log ("Reset Coins To 100 Count");
}
public void AddCoins(int amount)
{
Coins += amount;
// Store new coin value
PlayerPrefs.SetInt(COINS, Coins);
// Fire event
CoinsUpdated(Coins);
Debug.Log("Coins Have Been Added");
}
public void RemoveCoins(int amount)
{
Coins -= amount;
// Store new coin value
PlayerPrefs.SetInt(COINS, Coins);
// Fire event
CoinsUpdated(Coins);
}
}
On the button, I have the call function "AddCoins" to update the coins counter after a purchase is completed.
I have included a few images to view
Any thoughts would be helpful. Thanks