79 lines
2.0 KiB
C#
79 lines
2.0 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class JoyStickController : MonoBehaviour
|
|||
|
{
|
|||
|
public GameObject rightJoystick_obj;
|
|||
|
public Button rightremote;
|
|||
|
public GameObject FixedJoystick_obj;
|
|||
|
public GameObject lockedFixedJoystick_obj;
|
|||
|
|
|||
|
public Text timerText; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>UI<55>ı<EFBFBD>
|
|||
|
public float countdownTime = 30f; // <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʱ30<33><30>
|
|||
|
private float timeRemaining;
|
|||
|
private bool isCountingDown = false;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
|
|||
|
FixedJoystick_obj.gameObject.SetActive(false);//<2F><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>ʼʱ<CABC><CAB1><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>ҡ<EFBFBD>˹ر<CBB9><D8B1><EFBFBD>ʾ
|
|||
|
timeRemaining = countdownTime;
|
|||
|
rightJoystick_obj.gameObject.SetActive(false);
|
|||
|
rightremote.onClick.AddListener(OnClickRightRemote);
|
|||
|
isCountingDown = true;
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
if (isCountingDown)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ
|
|||
|
timeRemaining -= Time.deltaTime;
|
|||
|
|
|||
|
// ʱ<>䵽<EFBFBD><E4B5BD>0ʱ<30><CAB1>ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|||
|
if (timeRemaining <= 0)
|
|||
|
{
|
|||
|
timeRemaining = 0;
|
|||
|
isCountingDown = false;
|
|||
|
OnCountdownEnd(); // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ
|
|||
|
UpdateTimerDisplay();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void OnClickRightRemote()
|
|||
|
{
|
|||
|
rightJoystick_obj.gameObject.SetActive(true);
|
|||
|
rightremote.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>ʱUI<55><49>ʾ
|
|||
|
private void UpdateTimerDisplay()
|
|||
|
{
|
|||
|
int minutes = Mathf.FloorToInt(timeRemaining / 60);
|
|||
|
int seconds = Mathf.FloorToInt(timeRemaining % 60);
|
|||
|
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>¼<EFBFBD>
|
|||
|
private void OnCountdownEnd()
|
|||
|
{
|
|||
|
FixedJoystick_obj.gameObject.SetActive(true);
|
|||
|
lockedFixedJoystick_obj.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʱ
|
|||
|
public void ResetCountdown()
|
|||
|
{
|
|||
|
timeRemaining = countdownTime;
|
|||
|
isCountingDown = true;
|
|||
|
}
|
|||
|
}
|