質問するログイン新規登録

質問編集履歴

2

2019/02/10 10:30

投稿

sai26
sai26

スコア13

title CHANGED
File without changes
body CHANGED
@@ -7,8 +7,56 @@
7
7
 
8
8
  ### 該当のソースコード
9
9
 
10
+ ```C#
11
+
12
+ using System.Collections;
13
+ using System.Collections.Generic;
14
+ using UnityEngine;
15
+ using UnityEngine.UI;
16
+ using UnityEngine.SceneManagement;
17
+
18
+ public class Timecount : MonoBehaviour {
19
+
20
+ private int minute;
21
+ private float seconds;
22
+ //前のUpdate時の秒数
23
+ private float oldSeconds;
24
+ //タイマー表示テキスト
25
+ private Text timerText;
26
+
27
+ // Use this for initialization
28
+ void Start () {
29
+ minute = 1;
10
- ```ここに言語名を入力
30
+ seconds = 0;
31
+ oldSeconds = 0;
32
+ timerText = this.GetComponent<Text>();//Textコンポーネントを取得
33
+
34
+ }
35
+
36
+ // Update is called once per frame
37
+ void Update () {
38
+ seconds -= Time.deltaTime;
39
+ if (seconds <= 0f)
40
+ {
11
- ソースコード
41
+ minute--;
42
+ seconds = seconds +60;
43
+ }
44
+
45
+ //値が変わった時のみテキストUIを更新
46
+ if ((int)seconds != (int)oldSeconds)
47
+ {
48
+ timerText.text=minute.ToString("00")+":"+((int)seconds).ToString("00");
49
+ }
50
+ oldSeconds = seconds;
51
+ if (minute == 0 && seconds >= 0)
52
+ {
53
+ SceneManager.LoadScene("Result");
54
+ }
55
+
56
+ }
57
+
58
+ }
59
+
12
60
  ```
13
61
 
14
62
  ### 試したこと

1

2019/02/10 10:30

投稿

sai26
sai26

スコア13

title CHANGED
File without changes
body CHANGED
File without changes