質問編集履歴
6
書式の改善
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
SetActiveでオブジェクトを非表示にしてもスクリプトのコードを続けたい
|
test
CHANGED
@@ -1,135 +1,5 @@
|
|
1
|
-
|
1
|
+
タイトルの通り、SetActive、透明度変更以外でPanelを透明(または削除)させたいです。
|
2
2
|
|
3
|
-
|
3
|
+
SetActiveでオブジェクトを非表示にしてしまうと、スクリプトに書いていたSetActiveより下のコードの機能が止まってしまうので困っています。
|
4
4
|
|
5
|
-
|
5
|
+
調べてみても有力な情報が出てこないので質問させていただきます。
|
6
|
-
|
7
|
-
ご教授願います。
|
8
|
-
|
9
|
-
```c#
|
10
|
-
|
11
|
-
using System.Collections;
|
12
|
-
|
13
|
-
using System.Collections.Generic;
|
14
|
-
|
15
|
-
using UnityEngine;
|
16
|
-
|
17
|
-
using UnityEngine.UI;
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
public class CubeController : MonoBehaviour { //プレイヤーにアタッチしているスクリプト
|
22
|
-
|
23
|
-
private Rigidbody2D rb2D;
|
24
|
-
|
25
|
-
private float jumpForce = 4.0f;
|
26
|
-
|
27
|
-
public GameObject Score;
|
28
|
-
|
29
|
-
public GameObject EndPanel;
|
30
|
-
|
31
|
-
private bool gameover = false;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
private void Start () {
|
36
|
-
|
37
|
-
gameObject.SetActive (true);
|
38
|
-
|
39
|
-
rb2D = GetComponent<Rigidbody2D>();
|
40
|
-
|
41
|
-
EndPanel.gameObject.SetActive(false);
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
void Update () {
|
48
|
-
|
49
|
-
//gameoverフラグがtrueになった時、ジャンプできないようにする
|
50
|
-
|
51
|
-
if (Input.GetMouseButtonDown (0) && !gameover) {
|
52
|
-
|
53
|
-
Jump ();
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
void Jump(){
|
62
|
-
|
63
|
-
rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
void OnCollisionEnter2D (Collision2D collision) {
|
70
|
-
|
71
|
-
gameover = true;
|
72
|
-
|
73
|
-
EndPanel.gameObject.SetActive(true);
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
void OnTriggerEnter2D (Collider2D col) {
|
80
|
-
|
81
|
-
//Score(GUIText)のScoreUpメソッドを呼び出す
|
82
|
-
|
83
|
-
Score.SendMessage ("ScoreUp", 1);
|
84
|
-
|
85
|
-
Destroy (col.gameObject);
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
```
|
92
|
-
|
93
|
-
```c#
|
94
|
-
|
95
|
-
using UnityEngine;
|
96
|
-
|
97
|
-
using UnityEngine.UI;
|
98
|
-
|
99
|
-
using System.Collections;
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
public class ScoreScript : MonoBehaviour { //ScoreTextにアタッチしているスクリプト
|
104
|
-
|
105
|
-
public int score = 0;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
void Start () {
|
110
|
-
|
111
|
-
GetComponent<Text>().text = score.ToString();
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
public void ScoreUp (int point) {
|
118
|
-
|
119
|
-
score += point;
|
120
|
-
|
121
|
-
Endscore += point;
|
122
|
-
|
123
|
-
GetComponent<Text>().text = score.ToString();
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
### 追記
|
132
|
-
|
133
|
-
ゲームオーバーになる前はパネルはSetActiveで非表示にしていて、ゲームオーバになると表示されます。
|
134
|
-
|
135
|
-
SetActiveが非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアをresultTextに代入させたいのですが上手くいかず困っています。
|
5
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -132,4 +132,4 @@
|
|
132
132
|
|
133
133
|
ゲームオーバーになる前はパネルはSetActiveで非表示にしていて、ゲームオーバになると表示されます。
|
134
134
|
|
135
|
-
SetActiveが非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアを
|
135
|
+
SetActiveが非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアをresultTextに代入させたいのですが上手くいかず困っています。
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,6 +130,6 @@
|
|
130
130
|
|
131
131
|
### 追記
|
132
132
|
|
133
|
-
ゲームオーバーになる前はパネルはSe
|
133
|
+
ゲームオーバーになる前はパネルはSetActiveで非表示にしていて、ゲームオーバになると表示されます。
|
134
134
|
|
135
|
-
非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアを変更したいのですが上手くいかず困っています。
|
135
|
+
SetActiveが非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアを変更したいのですが上手くいかず困っています。
|
3
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,9 @@
|
|
127
127
|
}
|
128
128
|
|
129
129
|
```
|
130
|
+
|
131
|
+
### 追記
|
132
|
+
|
133
|
+
ゲームオーバーになる前はパネルはSeSetActiveで非表示にしていて、ゲームオーバになると表示されます。
|
134
|
+
|
135
|
+
非表示になっている時はスコアの値を変えたりすることが出来ないので、ゲームオーバになった時にスコアを変更したいのですが上手くいかず困っています。
|
2
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,125 +127,3 @@
|
|
127
127
|
}
|
128
128
|
|
129
129
|
```
|
130
|
-
|
131
|
-
```c#
|
132
|
-
|
133
|
-
using System.Collections;
|
134
|
-
|
135
|
-
using System.Collections.Generic;
|
136
|
-
|
137
|
-
using UnityEngine;
|
138
|
-
|
139
|
-
using UnityEngine.UI;
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
public class CubeController : MonoBehaviour { //プレイヤーにアタッチしているスクリプト
|
144
|
-
|
145
|
-
private Rigidbody2D rb2D;
|
146
|
-
|
147
|
-
private float jumpForce = 4.0f;
|
148
|
-
|
149
|
-
public GameObject Score;
|
150
|
-
|
151
|
-
public GameObject EndPanel;
|
152
|
-
|
153
|
-
private bool gameover = false;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
private void Start () {
|
158
|
-
|
159
|
-
gameObject.SetActive (true);
|
160
|
-
|
161
|
-
rb2D = GetComponent<Rigidbody2D>();
|
162
|
-
|
163
|
-
EndPanel.gameObject.SetActive(false);
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
void Update () {
|
170
|
-
|
171
|
-
//gameoverフラグがtrueになった時、ジャンプできないようにする
|
172
|
-
|
173
|
-
if (Input.GetMouseButtonDown (0) && !gameover) {
|
174
|
-
|
175
|
-
Jump ();
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
void Jump(){
|
184
|
-
|
185
|
-
rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
void OnCollisionEnter2D (Collision2D collision) {
|
192
|
-
|
193
|
-
gameover = true;
|
194
|
-
|
195
|
-
EndPanel.gameObject.SetActive(true);
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
void OnTriggerEnter2D (Collider2D col) {
|
202
|
-
|
203
|
-
//Score(GUIText)のScoreUpメソッドを呼び出す
|
204
|
-
|
205
|
-
Score.SendMessage ("ScoreUp", 1);
|
206
|
-
|
207
|
-
Destroy (col.gameObject);
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
```
|
214
|
-
|
215
|
-
```c#
|
216
|
-
|
217
|
-
using UnityEngine;
|
218
|
-
|
219
|
-
using UnityEngine.UI;
|
220
|
-
|
221
|
-
using System.Collections;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
public class ScoreScript : MonoBehaviour { //ScoreTextにアタッチしているスクリプト
|
226
|
-
|
227
|
-
public int score = 0;
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
void Start () {
|
232
|
-
|
233
|
-
GetComponent<Text>().text = score.ToString();
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
public void ScoreUp (int point) {
|
240
|
-
|
241
|
-
score += point;
|
242
|
-
|
243
|
-
Endscore += point;
|
244
|
-
|
245
|
-
GetComponent<Text>().text = score.ToString();
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
```
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
他のオブジェクトがプレイヤーとぶつかった時、ゲームオーバーになりスコアなどが記載されたパネルを表示するスクリプトを作成しました。
|
2
2
|
|
3
|
-
ゲームオーバになる前はScoreTextというTextにスコアを記載し、
|
3
|
+
ゲームオーバになる前はScoreTextというTextにスコアを記載し、ゲームオーバーになったらパネルに入っているresultTextというTextにスコアを記載させたいです。
|
4
|
+
|
5
|
+
しかし、調べてみても有力な情報が得られずに困っています。
|
6
|
+
|
7
|
+
ご教授願います。
|
4
8
|
|
5
9
|
```c#
|
6
10
|
|
@@ -123,3 +127,125 @@
|
|
123
127
|
}
|
124
128
|
|
125
129
|
```
|
130
|
+
|
131
|
+
```c#
|
132
|
+
|
133
|
+
using System.Collections;
|
134
|
+
|
135
|
+
using System.Collections.Generic;
|
136
|
+
|
137
|
+
using UnityEngine;
|
138
|
+
|
139
|
+
using UnityEngine.UI;
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
public class CubeController : MonoBehaviour { //プレイヤーにアタッチしているスクリプト
|
144
|
+
|
145
|
+
private Rigidbody2D rb2D;
|
146
|
+
|
147
|
+
private float jumpForce = 4.0f;
|
148
|
+
|
149
|
+
public GameObject Score;
|
150
|
+
|
151
|
+
public GameObject EndPanel;
|
152
|
+
|
153
|
+
private bool gameover = false;
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
private void Start () {
|
158
|
+
|
159
|
+
gameObject.SetActive (true);
|
160
|
+
|
161
|
+
rb2D = GetComponent<Rigidbody2D>();
|
162
|
+
|
163
|
+
EndPanel.gameObject.SetActive(false);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
void Update () {
|
170
|
+
|
171
|
+
//gameoverフラグがtrueになった時、ジャンプできないようにする
|
172
|
+
|
173
|
+
if (Input.GetMouseButtonDown (0) && !gameover) {
|
174
|
+
|
175
|
+
Jump ();
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
void Jump(){
|
184
|
+
|
185
|
+
rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
void OnCollisionEnter2D (Collision2D collision) {
|
192
|
+
|
193
|
+
gameover = true;
|
194
|
+
|
195
|
+
EndPanel.gameObject.SetActive(true);
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
void OnTriggerEnter2D (Collider2D col) {
|
202
|
+
|
203
|
+
//Score(GUIText)のScoreUpメソッドを呼び出す
|
204
|
+
|
205
|
+
Score.SendMessage ("ScoreUp", 1);
|
206
|
+
|
207
|
+
Destroy (col.gameObject);
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
```c#
|
216
|
+
|
217
|
+
using UnityEngine;
|
218
|
+
|
219
|
+
using UnityEngine.UI;
|
220
|
+
|
221
|
+
using System.Collections;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
public class ScoreScript : MonoBehaviour { //ScoreTextにアタッチしているスクリプト
|
226
|
+
|
227
|
+
public int score = 0;
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
void Start () {
|
232
|
+
|
233
|
+
GetComponent<Text>().text = score.ToString();
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
public void ScoreUp (int point) {
|
240
|
+
|
241
|
+
score += point;
|
242
|
+
|
243
|
+
Endscore += point;
|
244
|
+
|
245
|
+
GetComponent<Text>().text = score.ToString();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
```
|