質問編集履歴

3

画像を載せました

2023/02/22 15:47

投稿

Sakurami
Sakurami

スコア2

test CHANGED
File without changes
test CHANGED
@@ -19,11 +19,12 @@
19
19
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/f2c52554-7928-4802-baed-2907b840a086.png)
20
20
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/d7056297-5e9d-406b-a849-a45f6d035a0f.png)
21
21
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/fa4341f5-9f8d-4720-a73a-e08a37847444.png)
22
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/c3050689-d56b-49f7-9912-7d32cd744fb5.png)
22
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/7ce86566-8edb-4651-848b-3f106862e284.png)
23
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/9b15bccc-8117-4d4f-b981-1177e50631ee.png)
23
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/476fe5de-b5f2-4118-adcd-0bf15595a573.png)
24
24
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/73fc46f1-49e4-462c-8210-2e522bb9b515.png)
25
25
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/75cbe1e4-c70f-4492-a658-d6a5109e97f6.png)
26
26
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/373163a9-0048-4af1-aeea-05b74b853d09.png)
27
+
27
28
 
28
29
  ### 該当のソースコード
29
30
 

2

画像で全文載せました

2023/02/22 15:37

投稿

Sakurami
Sakurami

スコア2

test CHANGED
File without changes
test CHANGED
@@ -15,6 +15,15 @@
15
15
  ### 発生している問題・エラーメッセージ
16
16
 
17
17
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/96106ac3-d88d-46ed-adde-74eef4ebf607.png)
18
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/cb7a1a36-6b37-4e2c-987a-cb0c418a5390.png)
19
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/f2c52554-7928-4802-baed-2907b840a086.png)
20
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/d7056297-5e9d-406b-a849-a45f6d035a0f.png)
21
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/fa4341f5-9f8d-4720-a73a-e08a37847444.png)
22
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/c3050689-d56b-49f7-9912-7d32cd744fb5.png)
23
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/9b15bccc-8117-4d4f-b981-1177e50631ee.png)
24
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/73fc46f1-49e4-462c-8210-2e522bb9b515.png)
25
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/75cbe1e4-c70f-4492-a658-d6a5109e97f6.png)
26
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/373163a9-0048-4af1-aeea-05b74b853d09.png)
18
27
 
19
28
  ### 該当のソースコード
20
29
 

1

ソースを全部載せました。エラー画像を載せています

2023/02/22 15:26

投稿

Sakurami
Sakurami

スコア2

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
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-02-23/96106ac3-d88d-46ed-adde-74eef4ebf607.png)
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
- InstantCharacters(commandText[1],int.Parse(commandText[2]));
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
- ChangeCharacters(commandText[1],int.Parse(commandText[2]));
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(commandText[1]);
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 RunAwayCharacters()
95
+ IEnumerator ChangeBackGround()
109
96
  {
110
- yield return null;
97
+ isNext = false;
98
+ yield return new WaitForSeconds(waitTime * waitTimeTimes);
111
- if(this.isMove) {
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
- if(charTransform.x >= 500f || Input.GetMouseButtonDown(1)) {
101
+ string backPath = this.backGroundPath + this.commandText[1];
117
- //位置が500を超えるかマウスが押されたら破壊して終了
118
- DestroyCharacters(currentPos);
119
- isMove = true;
120
- break;
121
- }
122
- RectTransform charRect;
123
- charRect = this.characters[currentPos].GetComponent<RectTransform>();
102
+ Image image = backGroundObject.GetComponent<Image>();
103
+ image.sprite = Resources.Load<Sprite>(backPath);
104
+ Debug.Log(backPath);
124
105
 
125
- yield return null;
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
- isMove = true;
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
- ### 補足情報(FW/ツールのバージョンなど)
123
+ ,Quaternion.identity);
124
+ this.characters[currentPos].gameObject.name = "Character" + currentPos.ToString();
155
125
 
156
- Unity: LTS Release2021.3.18f1
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
+