using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Kedu : MonoBehaviour
{
private float zz;
//垂直方向的增量
private float number;
//位置数值
private float numberChange;
//读数显示数值
private float kk = 0;
//角度变量
public InputField inputTxt;
//输入框
private float inputTxtNumber;
public GameObject ban;
//对错版
public Image dui;
//对
public Image cuo;
//错
public Button btn;
//按钮
private void Start()
{
ban.SetActive(false);
//刚开始对错版不显示
}
private void OnMouseDown()
{
zz = 0;
//增量为零
}
private void Update()
{
zz = -Input.GetAxis("Mouse Y");
}
private void OnMouseDrag()
{
//算法
// print("开始拖拽!");
transform.Rotate(zz * 3, 0, 0);
kk += zz * 3;
transform.localPosition = new Vector3(-kk / 7200, 0, 0);
}
//数值检测
public void numberText()
{
//实际读数,获取子物体的坐标
number = 25 + transform.localPosition.x * 10;
//保留三位小数
numberChange = (float)(Mathf.Round(number * 1000)) / 1000;
print("实际数值:" + numberChange);
if (inputTxt.text == "")
{
inputTxtNumber = 0f;
print("输入错误!");
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
else
{
try
{
inputTxtNumber = float.Parse(inputTxt.text);
print("输入数值" + inputTxtNumber);
//字符串转化成float
}
catch
{
print("输入错误!");
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
}
float cha =Mathf .Abs (numberChange - inputTxtNumber);
print("差值!" + cha);
if (cha <= 0.005)
{
//显示正确
ban.SetActive(true);
dui.gameObject.SetActive(true);
cuo.gameObject.SetActive(false);
}
else
{
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Kedu : MonoBehaviour
{
private float zz;
//垂直方向的增量
private float number;
//位置数值
private float numberChange;
//读数显示数值
private float kk = 0;
//角度变量
public InputField inputTxt;
//输入框
private float inputTxtNumber;
public GameObject ban;
//对错版
public Image dui;
//对
public Image cuo;
//错
public Button btn;
//按钮
private void Start()
{
ban.SetActive(false);
//刚开始对错版不显示
}
private void OnMouseDown()
{
zz = 0;
//增量为零
}
private void Update()
{
zz = -Input.GetAxis("Mouse Y");
}
private void OnMouseDrag()
{
//算法
// print("开始拖拽!");
transform.Rotate(zz * 3, 0, 0);
kk += zz * 3;
transform.localPosition = new Vector3(-kk / 7200, 0, 0);
}
//数值检测
public void numberText()
{
//实际读数,获取子物体的坐标
number = 25 + transform.localPosition.x * 10;
//保留三位小数
numberChange = (float)(Mathf.Round(number * 1000)) / 1000;
print("实际数值:" + numberChange);
if (inputTxt.text == "")
{
inputTxtNumber = 0f;
print("输入错误!");
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
else
{
try
{
inputTxtNumber = float.Parse(inputTxt.text);
print("输入数值" + inputTxtNumber);
//字符串转化成float
}
catch
{
print("输入错误!");
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
}
float cha =Mathf .Abs (numberChange - inputTxtNumber);
print("差值!" + cha);
if (cha <= 0.005)
{
//显示正确
ban.SetActive(true);
dui.gameObject.SetActive(true);
cuo.gameObject.SetActive(false);
}
else
{
//显示错误
ban.SetActive(true);
dui.gameObject.SetActive(false);
cuo.gameObject.SetActive(true);
}
}
}