Untitled
unknown
plain_text
8 months ago
1.3 kB
14
Indexable
using UnityEngine;
public class CounterController : MonoBehaviour
{
[Header("UI")]
[SerializeField] private TextMesh counterText;
[Header("Bounds")]
[SerializeField] private int minValue = 1;
[SerializeField] private int maxValue = 5;
[Header("State")]
[SerializeField] private int currentValue = 1;
private void Awake()
{
// гарантируем, что стартовое значение в пределах
currentValue = Mathf.Clamp(currentValue, minValue, maxValue);
UpdateText();
}
// Метод для кнопки "стрелка вверх"
public void Increment()
{
if (currentValue < maxValue)
{
currentValue++;
UpdateText();
}
}
// Метод для кнопки "стрелка вниз"
public void Decrement()
{
if (currentValue > minValue)
{
currentValue--;
UpdateText();
}
}
private void UpdateText()
{
if (counterText != null)
counterText.text = currentValue.ToString();
else
Debug.LogWarning("CounterController: TextMesh не назначен в инспекторе.");
}
}Editor is loading...
Leave a Comment