Danro/Assets/Scripts/UI/UICreditsTextController.cs
Danil Iarosh 9555479967 feat(game): implement payment system and UI improvements
- Added PaymentManager integration with GameManager
- Implemented credit-based lives increment system
- Updated UI layout and anchor positions in MainMenu scene
- Added AddCredit input action bindings for keyboard and gamepad
- Refactored GameManager to use StartingLives, MaxLives properties
- Added UICreditsTextController for displaying credits and lives- Fixed prefab initialization order and component dependencies
- Updated ComWrapper serialization and prize checking logic
- Removed obsolete setLivesToDefaultAfterFirstLose setting
- Improved scene loading and player spawn management
2025-11-11 17:51:51 +03:00

40 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
{
UpdateCreditsText(0);
UpdateLivesText(0);
// Subscribe to events
PaymentManager.Instance?.OnCreditsChanged.AddListener(UpdateCreditsText);
PaymentManager.Instance?.OnCreditsChanged.AddListener(UpdateLivesText);
}
private void UpdateCreditsText(int creditsCount)
{
creditsText.text = string.Format(creditsString, creditsCount);
}
private void UpdateLivesText(int creditsCount)
{
int totalLives = creditsCount > 1 ?
GameManager.Instance.StartingLives + GameManager.Instance.LivesIncrement * (creditsCount - 1) :
GameManager.Instance.StartingLives;
livesText.text = string.Format(livesString, totalLives);
}
}