TimeChange
How do I use Time Change
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
65 | CancelInvoke ("TimeChange"); | 1 |
82 | private void TimeChange() { | 2 |
File name: TimerScript.cs
Copy
53 public void InitTimer() {
54 //set time remaining if it doesn't exist yet
55 if (!PlayerPrefs.HasKey ("timer_time_remaining")){
56 this.timeRemaining = PlayerPrefs.GetInt("options_timer_duration");
57 PlayerPrefs.SetInt ("timer_time_remaining", this.timeRemaining);
58 }
59 else {
60 this.timeRemaining = PlayerPrefs.GetInt ("timer_time_remaining");
61 }
62 PlayerPrefs.Save ();
63
64
65 CancelInvoke ("TimeChange");
66 if (PlayerPrefs.GetInt ("options_timer_duration") > 0) {
67 this.timerEnabled = true;
68 InvokeRepeating ("TimeChange", 1, 1);
69 }
70 else {
71 this.timerEnabled = false;
72 }
73 }
File name: TimerScript.cs
Copy
82 private void TimeChange() {
83 if (this.gameScript.gameView == "game"
84 && PlayerPrefs.GetString ("game_status") == "playing"
85 ) {
86 if(
87 this.options.play_sounds
88 && this.timeRemaining <= 6
89 && this.timeRemaining > 1
90 ) {
91 this.countdownAudioSource.Play();
92 }
93 if(this.timeRemaining == 1) {
94 PlayerPrefs.SetString ("game_status", "game_over");
95 }
96 this.timeRemaining = this.timeRemaining - 1;
97 }
98
99 PlayerPrefs.SetInt ("timer_time_remaining", this.timeRemaining);
100 PlayerPrefs.Save ();
101
102 }
TimeChange 139 lượt xem
Gõ tìm kiếm nhanh...