回答編集履歴
2
文法の修正
test
CHANGED
@@ -54,7 +54,6 @@
|
|
54
54
|
|
55
55
|
void Start()
|
56
56
|
{
|
57
|
-
//現在のstage_numを呼び出す
|
58
57
|
minute = PlayerPrefs.GetFloat("MINUTE", 0);
|
59
58
|
seconds = PlayerPrefs.GetFloat("SECOND", 0);
|
60
59
|
}
|
1
実装してみた例
test
CHANGED
@@ -1,3 +1,98 @@
|
|
1
1
|
[is missing the class attribute 'ExtensionOfNativeClass'!](https://teratail.com/questions/322531)
|
2
2
|
こちらのサイトが参考になるかと思います。
|
3
3
|
TimeCountがMonoBehaviourを継承したスクリプトではないためです。
|
4
|
+
|
5
|
+
```C#
|
6
|
+
using UnityEngine;
|
7
|
+
using UnityEngine.UI;
|
8
|
+
|
9
|
+
public class Timer : MonoBehaviour
|
10
|
+
{
|
11
|
+
[SerializeField] private int minute;
|
12
|
+
[SerializeField] private float seconds;
|
13
|
+
// 前のUpdateの時の秒数
|
14
|
+
private float oldSeconds;
|
15
|
+
// タイマー表示用テキスト
|
16
|
+
private Text timerText;
|
17
|
+
// 最初の時間
|
18
|
+
private float startTime;
|
19
|
+
|
20
|
+
void Start()
|
21
|
+
{
|
22
|
+
minute = 0;
|
23
|
+
seconds = 0f;
|
24
|
+
oldSeconds = 0f;
|
25
|
+
timerText = GetComponentInChildren<Text>();
|
26
|
+
startTime = Time.time;
|
27
|
+
}
|
28
|
+
|
29
|
+
void Update()
|
30
|
+
{
|
31
|
+
// Time.timeでの時間計測
|
32
|
+
seconds = Time.time - startTime;
|
33
|
+
|
34
|
+
minute = (int)seconds / 60;
|
35
|
+
|
36
|
+
if ((int)seconds != (int)oldSeconds)
|
37
|
+
{
|
38
|
+
timerText.text = minute.ToString("00") + ":" + ((int)(seconds % 60)).ToString("00");
|
39
|
+
}
|
40
|
+
oldSeconds = seconds;
|
41
|
+
|
42
|
+
PlayerPrefs.SetFloat("MINUTE", minute);
|
43
|
+
PlayerPrefs.SetFloat("SECOND", oldSeconds);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
47
|
+
```C#
|
48
|
+
using UnityEngine;
|
49
|
+
|
50
|
+
public class ScoreGet : MonoBehaviour
|
51
|
+
{
|
52
|
+
public static float minute = 0;
|
53
|
+
public static float seconds = 0;
|
54
|
+
|
55
|
+
void Start()
|
56
|
+
{
|
57
|
+
//現在のstage_numを呼び出す
|
58
|
+
minute = PlayerPrefs.GetFloat("MINUTE", 0);
|
59
|
+
seconds = PlayerPrefs.GetFloat("SECOND", 0);
|
60
|
+
}
|
61
|
+
|
62
|
+
public static float GetMinute()
|
63
|
+
{
|
64
|
+
return minute;
|
65
|
+
}
|
66
|
+
public static float GetSeconds()
|
67
|
+
{
|
68
|
+
return seconds;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
```C#
|
73
|
+
using UnityEngine;
|
74
|
+
using UnityEngine.UI;
|
75
|
+
|
76
|
+
public class TotalScore : MonoBehaviour
|
77
|
+
{
|
78
|
+
public Text scoreText;
|
79
|
+
float minute;
|
80
|
+
float seconds;
|
81
|
+
private float oldSeconds;
|
82
|
+
|
83
|
+
void Start()
|
84
|
+
{
|
85
|
+
minute = ScoreGet.GetMinute();
|
86
|
+
seconds = ScoreGet.GetSeconds();
|
87
|
+
}
|
88
|
+
|
89
|
+
private void Update()
|
90
|
+
{
|
91
|
+
if ((int)seconds != (int)oldSeconds)
|
92
|
+
{
|
93
|
+
scoreText.text = minute.ToString("00") + ":" + ((int)(seconds % 60)).ToString("00");
|
94
|
+
}
|
95
|
+
oldSeconds = seconds;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
```
|