ready动画结束后游戏开始,开始计时,直到死亡或者胜利再暂停计时。
新建ClearTime脚本用来更新时间文本,开始动画过后再计时
public class ClearTime : MonoBehaviour { [SerializeField] Text timeText; [SerializeField] VoidEventChannel levelStartedEventChannel; [SerializeField] VoidEventChannel levelClearedEventChannel; [SerializeField] StringEventChannel cleardTimeTextEventChannel; [SerializeField] VoidEventChannel playerDefeatedEventChannel; float clearTime; bool stop = true;
private void OnEnable() { levelStartedEventChannel.AddListener(LevelStart); levelClearedEventChannel.AddListener(levelCleared); playerDefeatedEventChannel.AddListener(HideUI); } private void OnDisable() { levelStartedEventChannel.RemoveListener(LevelStart); levelClearedEventChannel.RemoveListener(levelCleared); playerDefeatedEventChannel.RemoveListener(HideUI); } private void FixedUpdate() { if (stop) return; clearTime += Time.fixedDeltaTime; timeText.text = System.TimeSpan.FromSeconds(clearTime).ToString(@"mm\:ss\:ff"); } void LevelStart() { stop = false; } void levelCleared() { HideUI(); cleardTimeTextEventChannel.Broadcast(timeText.text); } void HideUI() { stop = true; GetComponent<Canvas>().enabled = false; } }
|
过关时间显示在Victory Screen