-
Notifications
You must be signed in to change notification settings - Fork 0
/
dis_kaeru.cs
68 lines (60 loc) · 2.06 KB
/
dis_kaeru.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
using TMPro;
using System.Collections;
using System.Text;
public class dis_kaeru : MonoBehaviour
{
public TextMeshProUGUI targetText;
public float fadeDuration = 0.2f; // フェードの持続時間
public string file_name = "kaeru";
public TextAsset textAsset;
public string data;
public int count = 0;
private void Start()
{
TextAsset textAsset = Resources.Load<TextAsset>(file_name);
data = textAsset.text;
StartCoroutine(IncrementEvery10Seconds());
}
void Update()
{
// 書き込み
string[] arr = data.Split('\n');
string newDisplayStr = "・" + arr[count % 100];
// テキストが変わったときにフェード処理を行う
if (targetText.text != newDisplayStr)
{
StartCoroutine(FadeText(targetText, newDisplayStr));
}
}
IEnumerator FadeText(TextMeshProUGUI textMesh, string newText)
{
// フェードアウト
Color originalColor = textMesh.color;
for (float t = 0; t < fadeDuration; t += Time.deltaTime)
{
float normalizedTime = t / fadeDuration;
textMesh.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1 - normalizedTime);
yield return null;
}
textMesh.color = new Color(originalColor.r, originalColor.g, originalColor.b, 0);
// テキストの更新
textMesh.text = newText;
// フェードイン
for (float t = 0; t < fadeDuration; t += Time.deltaTime)
{
float normalizedTime = t / fadeDuration;
textMesh.color = new Color(originalColor.r, originalColor.g, originalColor.b, normalizedTime);
yield return null;
}
textMesh.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1);
}
IEnumerator IncrementEvery10Seconds()
{
while (true) // 無限ループ
{
yield return new WaitForSeconds(5f); // 10秒待つ
count++; // インクリメント
}
}
}