質問編集履歴
3
画像を載せました
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,11 +19,12 @@
|
|
19
19
|

|
20
20
|

|
21
21
|

|
22
|
-

|
23
|
-

|
24
24
|

|
25
25
|

|
26
26
|

|
27
|
+
|
27
28
|
|
28
29
|
### 該当のソースコード
|
29
30
|
|
2
画像で全文載せました
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,6 +15,15 @@
|
|
15
15
|
### 発生している問題・エラーメッセージ
|
16
16
|
|
17
17
|

|
18
|
+

|
19
|
+

|
20
|
+

|
21
|
+

|
22
|
+

|
23
|
+

|
24
|
+

|
25
|
+

|
26
|
+

|
18
27
|
|
19
28
|
### 該当のソースコード
|
20
29
|
|
1
ソースを全部載せました。エラー画像を載せています
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,153 +5,134 @@
|
|
5
5
|
本文を表示する場合はクリック待ち、コマンド実行の場合は入力なしで自動で実行されるようにしたいのですが、
|
6
6
|
関数を実行するとエディターがフリーズしてしまいます。
|
7
7
|
エラー原因と思われる関数を記述してます。
|
8
|
+
追記1:フリーズは解決しました。次はテキスト行数参照用の変数iが変な値を表示してしまいます。
|
9
|
+
動きとしては最初にChangeBackGroundを呼び出して壁紙を表示、そのあとInstantCharactersでキャラを呼び出し、本文が表示されるのですが、ゲーム再生してクリックするとiが3から1400など突飛もない値になってしまいます。
|
8
10
|
|
9
11
|
### 実現したいこと
|
10
12
|
OnClickToNextString関数で最初のif文でマウス入力待ちをすればフリーズしなくなるのですが、コマンドは自動で実行されるようにしたいです
|
11
13
|
|
14
|
+
|
12
15
|
### 発生している問題・エラーメッセージ
|
13
16
|
|
14
|
-
|
17
|
+

|
15
18
|
|
16
19
|
### 該当のソースコード
|
17
20
|
|
18
21
|
```C#
|
19
|
-
using System.Collections;
|
20
|
-
using System.Collections.Generic;
|
21
|
-
using System;
|
22
|
-
using System.Linq;
|
23
|
-
using UnityEngine;
|
24
|
-
using UnityEngine.UI;
|
25
|
-
using UnityEngine.SceneManagement;
|
26
22
|
|
27
|
-
public class NovelManager : MonoBehaviour
|
28
|
-
{
|
29
|
-
TextAsset textAsset;
|
30
|
-
|
31
|
-
List<string> scenarioList = new List<string>();
|
32
|
-
string[] novelText; //本文表示用
|
33
|
-
string[] commandText; //コマンド識別用
|
34
|
-
string tmp; //仮文字列
|
35
|
-
int listLength; //リストサイズ
|
36
|
-
//float stringDisplaySpeed = 0.1f;
|
37
|
-
|
38
|
-
string backGroundPath = "BackGrounds/"; //壁紙ファイルのパス
|
39
|
-
string charactersPath = "Characters/"; //キャラクターファイルのパス
|
40
|
-
string prefabPath = "Prefabs/";
|
41
|
-
string currentSceneName;
|
42
|
-
|
43
|
-
GameObject mainTextObject;
|
44
|
-
GameObject nameTextObject;
|
45
|
-
GameObject backGroundObject;
|
46
|
-
GameObject canvas;
|
47
|
-
GameObject BlackOut;
|
48
|
-
|
49
|
-
GameObject[] characters;
|
50
|
-
float charImagePositionY = 20.0f;
|
51
|
-
float[] charImagePositionX = {320f,160f,10f,-140f,-310f};
|
52
|
-
|
53
|
-
int currentPos; // "
|
54
|
-
int toMovePos; //キャラムーブ用の変数
|
55
|
-
bool isMove; //キャラムーブトリガー
|
56
|
-
bool isNext = true;
|
57
|
-
float charMoveSpeed = 5f;
|
58
|
-
|
59
|
-
int i; //現在見ている箇所を確認する用
|
60
|
-
|
61
|
-
void Update()
|
62
|
-
{
|
63
|
-
StartCoroutine("OnClickToNextString");
|
64
|
-
SortOrderCharImage(backGroundObject);
|
65
|
-
Debug.Log(isMove);
|
66
|
-
}
|
67
23
|
|
68
24
|
IEnumerator OnClickToNextString()
|
69
25
|
{
|
26
|
+
|
70
27
|
if(/*Input.GetMouseButtonDown(0) &&*/ isMove && isNext) {
|
71
|
-
isNext = false;
|
28
|
+
//isNext = false;
|
72
29
|
tmp = scenarioList[i];
|
73
30
|
if(tmp[0] == '#') { //コマンドだったら
|
74
31
|
tmp = tmp.Remove(0,1);
|
75
32
|
commandText = tmp.Split(' ');
|
76
33
|
if(commandText[0] == "SetChara") {
|
77
|
-
|
34
|
+
this.currentPos = int.Parse(commandText[2]);
|
35
|
+
|
36
|
+
bool isNumber = float.TryParse(commandText[3],out this.waitTimeTimes);
|
37
|
+
if(isNumber == false)
|
38
|
+
this.waitTimeTimes = 1f;
|
39
|
+
|
40
|
+
StartCoroutine("InstantCharacters");
|
78
41
|
} else if(commandText[0] == "RefChara") {
|
79
|
-
|
42
|
+
this.currentPos = int.Parse(commandText[2]);
|
43
|
+
|
44
|
+
bool isNumber = float.TryParse(commandText[3],out this.waitTimeTimes);
|
45
|
+
if(isNumber == false)
|
46
|
+
this.waitTimeTimes = 1f;
|
47
|
+
|
48
|
+
StartCoroutine("ChangeCharacters");
|
80
49
|
} else if(commandText[0] == "SetBack") {
|
50
|
+
bool isNumber = float.TryParse(commandText[2],out this.waitTimeTimes);
|
51
|
+
if(isNumber == false)
|
52
|
+
this.waitTimeTimes = 1f;
|
53
|
+
|
81
|
-
ChangeBackGround
|
54
|
+
StartCoroutine("ChangeBackGround");
|
82
55
|
} else if(commandText[0] == "RemChara") {
|
83
56
|
DestroyCharacters(int.Parse(commandText[1]));
|
84
57
|
} else if(commandText[0] == "MovChara") {
|
85
58
|
this.currentPos = int.Parse(commandText[1]);
|
86
59
|
this.toMovePos = int.Parse(commandText[2]);
|
60
|
+
|
61
|
+
bool isNumber = float.TryParse(commandText[3],out this.waitTimeTimes);
|
62
|
+
if(isNumber == false)
|
63
|
+
this.waitTimeTimes = 1f;
|
64
|
+
|
87
65
|
StartCoroutine("MoveCharacters");
|
88
66
|
} else if(commandText[0] == "RunAway") {
|
89
67
|
this.currentPos = int.Parse(commandText[2]);
|
68
|
+
|
69
|
+
bool isNumber = float.TryParse(commandText[3],out this.waitTimeTimes);
|
70
|
+
if(isNumber == false)
|
71
|
+
this.waitTimeTimes = 1f;
|
72
|
+
|
90
73
|
StartCoroutine("RunAwayCharacters");
|
91
74
|
} else if(commandText[0] == "OutScreen") {
|
75
|
+
bool isNumber = float.TryParse(commandText[3],out this.waitTimeTimes);
|
76
|
+
if(isNumber == false)
|
77
|
+
this.waitTimeTimes = 1f;
|
78
|
+
|
92
79
|
StartCoroutine("ScreenBlackOut");
|
93
80
|
}
|
94
|
-
this.i++;
|
81
|
+
//this.i++;
|
95
82
|
//コマンド用
|
96
83
|
} else { //コメントでもコマンドでもなければ
|
97
84
|
yield return new WaitUntil(() => Input.GetMouseButtonDown(0));
|
98
85
|
StartCoroutine("MainStringDisplay");
|
99
86
|
|
100
|
-
this.i++;
|
87
|
+
//this.i++;
|
101
88
|
}
|
102
|
-
//this.i++;
|
103
|
-
//StartCoroutine("OnClickToNextString");
|
104
89
|
isNext = true;
|
90
|
+
yield return null;
|
91
|
+
i++;
|
105
92
|
}
|
106
93
|
}
|
107
94
|
|
108
|
-
IEnumerator
|
95
|
+
IEnumerator ChangeBackGround()
|
109
96
|
{
|
110
|
-
|
97
|
+
isNext = false;
|
98
|
+
yield return new WaitForSeconds(waitTime * waitTimeTimes);
|
111
|
-
if(
|
99
|
+
if(isMove) {
|
112
100
|
isMove = false;
|
113
|
-
while(true) {
|
114
|
-
if(commandText[1] == "R") {
|
115
|
-
Vector3 charTransform = this.characters[currentPos].GetComponent<RectTransform>().localPosition;
|
116
|
-
|
101
|
+
string backPath = this.backGroundPath + this.commandText[1];
|
117
|
-
//位置が500を超えるかマウスが押されたら破壊して終了
|
118
|
-
DestroyCharacters(currentPos);
|
119
|
-
isMove = true;
|
120
|
-
break;
|
121
|
-
}
|
122
|
-
RectTransform charRect;
|
123
|
-
|
102
|
+
Image image = backGroundObject.GetComponent<Image>();
|
103
|
+
image.sprite = Resources.Load<Sprite>(backPath);
|
104
|
+
Debug.Log(backPath);
|
124
105
|
|
125
|
-
|
106
|
+
yield return null;
|
126
|
-
|
127
|
-
charTransform.x += charMoveSpeed;
|
128
|
-
charRect.localPosition = charTransform;
|
129
|
-
} else if(commandText[1] == "L") {
|
130
|
-
Vector3 charTransform = this.characters[currentPos].GetComponent<RectTransform>().localPosition;
|
131
|
-
if(charTransform.x <= -500f || Input.GetMouseButtonDown(0)) {
|
132
|
-
//位置が-500を下回るかマウスが押されたら破壊して終了
|
133
|
-
DestroyCharacters(currentPos);
|
134
|
-
|
107
|
+
isMove = true;
|
135
|
-
break;
|
136
|
-
}
|
137
|
-
RectTransform charRect;
|
138
|
-
charRect = this.characters[currentPos].GetComponent<RectTransform>();
|
139
|
-
|
140
|
-
yield return null;
|
141
|
-
|
142
|
-
charTransform.x -= charMoveSpeed;
|
143
|
-
charRect.localPosition = charTransform;
|
144
|
-
}
|
145
|
-
}
|
146
108
|
}
|
147
109
|
}
|
148
|
-
```
|
149
110
|
|
111
|
+
IEnumerator InstantCharacters()
|
112
|
+
{
|
113
|
+
isNext = false;
|
114
|
+
yield return new WaitForSeconds(waitTime * waitTimeTimes);
|
150
|
-
|
115
|
+
if(isMove) {
|
116
|
+
isMove = false;
|
151
117
|
|
152
|
-
|
118
|
+
string charPath = this.charactersPath + this.commandText[1];
|
119
|
+
string charPrefabPath = prefabPath + "Character1";
|
153
120
|
|
121
|
+
GameObject prefab = (GameObject)Resources.Load(charPrefabPath);
|
122
|
+
this.characters[currentPos] = Instantiate(prefab,new Vector3(charImagePositionX[currentPos],charImagePositionY,0f)
|
154
|
-
|
123
|
+
,Quaternion.identity);
|
124
|
+
this.characters[currentPos].gameObject.name = "Character" + currentPos.ToString();
|
155
125
|
|
156
|
-
|
126
|
+
this.characters[currentPos].transform.SetParent(this.canvas.transform,false);
|
157
127
|
|
128
|
+
this.characters[currentPos].GetComponent<Image>().sprite = Resources.Load<Sprite>(charPath);
|
129
|
+
|
130
|
+
SortOrderCharImage(this.characters[currentPos]);
|
131
|
+
|
132
|
+
yield return null;
|
133
|
+
isMove = true;
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
137
|
+
|
138
|
+
|