using System; using UnityEngine; using UnityEngine.UI; public class RealTimeTimeLimitChanger : MonoBehaviour { public GameObject Agent; public InputField TimeLimInputField; public Text TimeLimPlaceholder; public void BTPressed() { AgentWithGun agentWithGun = Agent.GetComponent(); InGameMessages messenger = gameObject.GetComponent(); int timeLimit = Math.Abs(int.Parse(TimeLimInputField.GetComponent().text)); if (TimeLimInputField.GetComponent().text == "-") { // input chara not illegal TimeLimPlaceholder.color = Color.red; TimeLimPlaceholder.text = "Wrong Type!"; TimeLimInputField.GetComponent().text = ""; messenger.SendMessagetoBox("Wrong timeLimit Type!", Message.MessageType.error); } else if (TimeLimInputField.GetComponent().text == "") { // empty chara TimeLimPlaceholder.color = Color.gray; TimeLimPlaceholder.text = "TimeLim"; } else { int remainTime = agentWithGun.remainTime; // make sure new timeLimit is greater than remainTime; if (timeLimit <= remainTime) { TimeLimPlaceholder.color = Color.red; TimeLimPlaceholder.text = "Error"; messenger.SendMessagetoBox($"New time should greater than remainTime({remainTime})",Message.MessageType.error); } else { // good to go~ TimeLimPlaceholder.color = Color.gray; TimeLimPlaceholder.text = "TimeLim"; agentWithGun.timeLimit = timeLimit; TimeLimInputField.GetComponent().text = ""; messenger.SendMessagetoBox($"Time Limit changed to {timeLimit}",Message.MessageType.success); } } } }