유니티/기능
인풋 필드 UI
MJ_119
2024. 6. 28. 21:56
- 금고 시스템 ( 입금, 출금 )
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEditor.UI;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField] TMP_Text text;
[SerializeField] TMP_InputField inputfield;
int total = 0;
public void Input()
{
if ((total + int.Parse(inputfield.text)) <= 99999) // 특정수 : 99999 이상 안들어가게 함
{
total += int.Parse(inputfield.text);
text.text = total.ToString();
}
}
public void Output()
{
if ( (total - int.Parse(inputfield.text)) >= 0 ) // 0 이하 금지
{
total -= int.Parse(inputfield.text);
text.text = total.ToString();
}
}
}