상세 컨텐츠

본문 제목

인풋 필드 UI

유니티/기능

by 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();
        }
    }
}

 

 

관련글 더보기