using System; using RR.Common.Managers; using RR.Game2D.Core.Managers; using TMPro; using UnityEngine; public class UICreditsTextController : MonoBehaviour { // UI elements [SerializeField] private TextMeshProUGUI creditsText; [SerializeField] private TextMeshProUGUI livesText; // Strings to display [SerializeField] private string creditsString = "У вас {0} кредитов"; [SerializeField] private string livesString = "У вас будет {0}"; private void Start() { PaymentManager paymentManager = PaymentManager.Instance; GameManager gameManager = GameManager.Instance; // Subscribe to events if (paymentManager != null) { UpdateCreditsText(paymentManager.CreditsCount); paymentManager.OnCreditsChanged.AddListener(UpdateCreditsText); } if (gameManager != null) { UpdateLivesText(gameManager.MaxLives); gameManager.MaxLivesChanged += (UpdateLivesText); } } private void OnDestroy() { PaymentManager paymentManager = PaymentManager.Instance; GameManager gameManager = GameManager.Instance; if (paymentManager != null) paymentManager.OnCreditsChanged.RemoveListener(UpdateCreditsText); if (gameManager != null) gameManager.MaxLivesChanged -= UpdateLivesText; } private void UpdateCreditsText(int creditsCount) { creditsText.text = string.Format(creditsString, creditsCount); } private void UpdateLivesText(int newLives) { livesText.text = string.Format(livesString, newLives); } }