InitTimer
How do I use Init Timer
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
19 | this.InitTimer (); | 1 |
53 | public void InitTimer() { | 2 |
76 | this.InitTimer (); | 3 |
File name: TimerScript.cs
Copy
15 void Start () {
16 this.gameScript = this.gameObject.GetComponent ("GameControllerScript") as GameControllerScript;
17 this.options = this.gameObject.GetComponent ("OptionsScript") as OptionsScript;
18 this.currentGUISkin = gameScript.currentGUISkin;
19 this.InitTimer ();
20
21 AudioSource[] audioSources = GetComponents
22 this.countdownAudioSource = audioSources[2];
23 countdownAudioSource.clip = this.countdownSound;
24 }
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
75 public void ResetTimer() {
76 this.InitTimer ();
77 this.timeRemaining = PlayerPrefs.GetInt ("options_timer_duration") + 5;
78 PlayerPrefs.SetInt ("timer_time_remaining", this.timeRemaining);
79 PlayerPrefs.Save();
80 }
InitTimer 158 lượt xem
Gõ tìm kiếm nhanh...