using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
public int score = 0;
public Text scoreText; // Сюда мы перетащим текст
void Awake()
{
Instance = this;
}
public void AddScore()
{
score++;
if (scoreText != null)
{
scoreText.text = "Очки: " + score; // Пишем текст и цифру
}
}
}
using UnityEngine;
public class Coin : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (GameManager.Instance != null)
{
GameManager.Instance.AddScore(); // Даем очко
}
Destroy(gameObject); // Удаляем монетку
}
}
}