当前位置:网站首页>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;
}边栏推荐
- What should testers do if they encounter a bug that is difficult to reproduce?
- mysql_ Record the executed SQL
- A 20 yuan facial cleanser sold tens of thousands in seven days. How did they do it?
- How to use two queues to simulate the implementation of a stack
- From input URL to page presentation
- C. Mark and His Unfinished Essay
- C language_ Structure introduction
- Leetcode programming practice -- Tencent selected 50 questions (I)
- Print the common part of two ordered linked lists
- [stm32f103rct6] can communication
猜你喜欢

How chemical enterprises choose digital service providers with dual prevention mechanism

Openlayers draw circles and ellipses

kettle_ Configure database connection_ report errors

Database transactions (often asked)

Eslint error

Preliminary foundation JVM

Swagger key configuration items

Force deduction brush question 7. Integer inversion

Flowlayout in compose

mysql_ Record the executed SQL
随机推荐
[stm32f103rct6] motor PWM drive module idea and code
Solve mysql5.6 database specified key was too long; Max key length is 767 bytes
Unified return data format
C language introduction practice (9): completion judgment
Recursive and non recursive methods are used to realize the first order, middle order and second order traversal of binary tree respectively
Sum of "n" numbers of force deduction summary
Riotboard development board series notes (VII) -- the use of framebuffer
Print the common part of two ordered linked lists
Take a database statement note: when the field is empty, assign the default value to the result
The dolphin scheduler calls the shell script and passes multiple parameters
Color space (2) -- YUV
Flink1.15 source code reading - Flink annotations
Sword finger offer II 041. Average value of sliding window_____ Using queue / loop array implementation
Can bus baud rate setting of stm32cubemx
Openlayers draw circles and ellipses
ES6 - study notes
Use and introduction of vim file editor
Test question C: question brushing statistics
JS method encapsulation summary
Web -- JDBC tool class writing