using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GongShuiNengLiCalculation : MonoBehaviour { public Text QResult; public Text NResult; public InputField DInput; public InputField VInput; public InputField QInput; public void OnCalculation() { if (DInput.text != string.Empty && VInput.text != string.Empty&&QInput.text!=string.Empty) { var result1 = Math.Pow(float.Parse(DInput.text) / 25, 2); result1 = 0.5f * result1 * float.Parse(VInput.text); //var result2 = result1.ToString("F2"); var result = $"{ Math.Round(result1, 4)}"; QResult.text = $" = {result}(L/s)"; var result3 = result1 / float.Parse(QInput.text); var result4 = Math.Ceiling(result3).ToString(); result4 = $"{result4}"; NResult.text = $" = {result4}(辆)"; } else { MessageBox.Show("参数不能为空!", Color.red, 2f); } } public void OnClear() { QResult.text = string.Empty; NResult.text = string.Empty; DInput.text = string.Empty; VInput.text = string.Empty; QInput.text = string.Empty; } }