using UnityEngine;
public class Coin : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
CoinText.Coin += 1;
Destroy(gameObject);
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class CoinText : MonoBehaviour
{
Text coinText;
public static int Coin;
void Start()
{
coinText = GetComponent();
Coin = PlayerPrefs.GetInt("Coins", Coin);
}
void Update()
{
coinText.text = Coin.ToString();
PlayerPrefs.SetInt("Coins", Coin);
}
}