zoukankan      html  css  js  c++  java
  • InputFiled中输入数值,text动态显示数值,当输入数值>text中数值,text中的数值动态递增;反之,动态递减。

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using System;
    /// <summary>
    /// 在输入框输入数字,在现实文本中数值动态增加,可多次输入
    /// InputFiled中输入数值,text动态显示数值,当输入数值>text中数值,text中的数值动态递增;反之,动态递减。
    /// </summary>
    
    public class T_DataSet : MonoBehaviour
    {
        /// <summary>
        /// 输入框
        /// </summary>
        public InputField Ipf1;
        /// <summary>
        /// 显示文本
        /// </summary>
        public Text txt1;
        //public Text txt2;
        bool Check = false;
        [NonSerialized]
        public float minimum;
        [NonSerialized]
        public float maximum;
        static float t = 0.0f;
        string RecordTxt;
        void Start()
        {
            minimum = int.Parse(txt1.text);
            Ipf1.onEndEdit.AddListener(delegate
            {
                this.EndData(Ipf1.gameObject);
            });
        }
       
        void Update()
        {
    
        }
        IEnumerator Timer()
        {
            while (Check)
            {
                RecordTxt = Mathf.Lerp(minimum, maximum, t).ToString("0.0");
                t += 1f * Time.deltaTime;
                if (RecordTxt == maximum.ToString("0.0"))
                {
                    t = 0.0f;
                    minimum = maximum;
                    Check = false;
                }
                txt1.text = RecordTxt;
                yield return new WaitForSeconds(0.1f);
            }
        }
        void EndData(GameObject game)
        {
            if (game == Ipf1.gameObject)
            {
                maximum = float.Parse(Ipf1.text);
                Check = true;
                StartCoroutine(Timer());
            }
        }
    }
  • 相关阅读:
    10-3 集合之Set
    【Angular】排序
    【Mongous】
    【验证码】
    爬虫
    【DOM】
    年月日
    【Mocha】
    【Test】
    洛谷——P1823 音乐会的等待
  • 原文地址:https://www.cnblogs.com/Cocomo/p/6861919.html
Copyright © 2011-2022 走看看