using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
button.onClick.AddListener(DDDD);
}
float time = 0;
// Update is called once per frame
void Update () {
if (isStart)
{
time += Time.deltaTime;//及时
text.text = string.Format("{0:D2}:{1:D2}",
(int)((float.Parse(inputField.text.Length > 0 ? inputField.text : "1") - time) / 60),
(int)((float.Parse(inputField.text.Length > 0 ? inputField.text : "1")+1 - time) % 60));
slider.value = time / float.Parse(inputField.text.Length > 0 ? inputField.text : "1");
Debug.Log(time);
if ((int)((float.Parse(inputField.text.Length > 0 ? inputField.text : "1") + 1 - time) % 60) <= 0)
{
text.text = "00:00";
isStart = false;
time = 0;
}
}
}
public Text text;
public Button button;
public Slider slider;
public InputField inputField;
bool isStart = false;
public void DDDD()
{
isStart = true;//点击按钮开始计时
}
///移动代码
//private Vector3 screenPos;
//private Vector3 offset;
//private Vector3 newPosition;
//bool isgenSUi = false;
//private void OnMouseDown()
//{
// //获取当前对象的屏幕坐标
// screenPos = Camera.main.WorldToScreenPoint(transform.position);
// offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));
//}
//private void OnMouseDrag()
//{
// isgenSUi = true;
//}
//private void FixedUpdate()
//{
// if (isgenSUi)
// {
// isgenSUi = false;
// transform.position = offset +
// Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));
// }
//}
}