当前位置:网站首页>Unity: text input box for numerical judgment
Unity: text input box for numerical judgment
2022-07-25 03:23:00 【Little sun works hard every day】
Achieve the goal : Judge the value in the input box
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Calculate : MonoBehaviour
{
public InputField zhiliangdenshu;// Mass fraction
public InputField dianya;// voltage
public InputField liuliang;// Traffic
public InputField pentou_d;// Nozzle diameter
public Text showText;
double dianyaValue;// Voltage value
double liuliangValue;// Flow value
double pentou_dValue;// Nozzle diameter
public void calculateValue()
{
if (IsSpace(zhiliangdenshu.text.ToString())||IsSpace(dianya.text.ToString())||IsSpace(liuliang.text.ToString()) ||IsSpace(liuliang.text.ToString()))// If it is empty
{
showText.text=" An entry is empty ";
lineShow.SetActive(false);
}
else
{
dianyaValue = Convert.ToDouble(dianya.text.ToString());//string To double
switch (zhiliangdenshu.text.ToString())//switch Judge the quality score text character string
{
case "4%":
if (( dianyaValue>15&&dianyaValue<19)&& (liuliangValue> 0.5f&&liuliangValue <2.0f) && (pentou_dValue> 0.5f&&pentou_dValue<1.0f))// Judge the value range
{
lineShow.transform.localScale = new Vector3(1.5f, 0.5f, 0.5f);
// Picture size and form settings
}
else
{
showText.text = " The input value is not within the measurement range ";
lineShow.SetActive(false);
}; break;
default:
showText.text = " The quality score is entered incorrectly ";
lineShow.SetActive(false);
break;
}
}
}
// Detect spaces
private bool IsSpace(string textValue)
{
if (textValue.Trim().Length == 0)// Remove the spaces at the beginning and end of the string
{
return true;
}
return false;
}边栏推荐
- Banana pie bpi-m5 toss record (3) -- compile BSP
- Implementation principle of virtual DOM
- Time formatting
- [golang] golang realizes sending wechat service number template messages
- mysql_ Account authorization permission recycling, account locking and unlocking, account creation and deletion
- Question B: shunzi date
- mysql_ Backup restore_ Specify table_ Backup table_ Restore table_ innobackup
- Why does the legend of superstar (Jay Chou) not constitute pyramid selling? What is the difference between distribution and pyramid selling?
- Uni app configuration
- Force deduction brush question 7. Integer inversion
猜你喜欢

How chemical enterprises choose digital service providers with dual prevention mechanism

Banana pie bpi-m5 toss record (3) -- compile BSP

What should testers do if they encounter a bug that is difficult to reproduce?
![[stm32f103rct6] can communication](/img/24/71509bd0d74d43ce4a79b8126478ff.jpg)
[stm32f103rct6] can communication

Bgy development small example

From input URL to page presentation
![[stm32f103rct6] motor PWM drive module idea and code](/img/a5/3010acff73c8913e967ff3a024877e.png)
[stm32f103rct6] motor PWM drive module idea and code

C language_ Defining structures and using variables

Force button brushing question 61. rotating linked list

JS construct binary tree
随机推荐
How to use two stacks to simulate the implementation of a queue
TypeScript
Riotboard development board series notes (VII) -- the use of framebuffer
[golang] golang realizes sending wechat service number template messages
Leetcode.745. prefix and suffix search____ Double dictionary tree + double pointer
Stm32cubemx quadrature encoder
B. Almost Ternary Matrix
Calculation method of confusion matrix
Experiment 4 CTF practice
mysql_ Backup restore_ Specify table_ Backup table_ Restore table_ innobackup
Force deduction brush question 26. Delete duplicates in the ordered array
What should testers do if they encounter a bug that is difficult to reproduce?
Publish the project online and don't want to open a port
File permission management
Openlayers draw deletes the last point when drawing
Use go language to import Doris data through stream load
Li Kou 279 complete square - dynamic programming
Li Kou 343 integer partition dynamic programming
Solve mysql5.6 database specified key was too long; Max key length is 767 bytes
NVM installation and use