質問編集履歴
1
オブジェクトを削除しているコードを記載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
+
|
3
|
+
|
2
4
|
|
3
5
|
UnityとPhotonを用いて通信対戦型のテトリスを作成しています。
|
4
6
|
|
@@ -22,91 +24,119 @@
|
|
22
24
|
|
23
25
|
###該当のソースコード
|
24
26
|
|
25
|
-
C#
|
26
27
|
|
27
28
|
|
29
|
+
```C#
|
28
30
|
|
29
|
-
public class
|
31
|
+
public class Grid1: Photon.PunBehaviour
|
30
32
|
|
31
33
|
{
|
32
34
|
|
33
35
|
|
34
36
|
|
35
|
-
public
|
37
|
+
public static int w = 10;
|
38
|
+
|
39
|
+
public static int h = 20;
|
40
|
+
|
41
|
+
public static Transform[,] grid = new Transform[w, h];
|
36
42
|
|
37
43
|
|
38
44
|
|
39
45
|
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
public
|
47
|
+
public static Vector2 roundVec2(Vector2 v)
|
44
48
|
|
45
49
|
{
|
46
50
|
|
51
|
+
return new Vector2(Mathf.Round(v.x), Mathf.Round(v.y));
|
52
|
+
|
53
|
+
}
|
47
54
|
|
48
55
|
|
56
|
+
|
57
|
+
public static bool insideBorder(Vector2 pos)
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
return ((int)pos.x >= 0 &&
|
62
|
+
|
63
|
+
(int)pos.x < w &&
|
64
|
+
|
65
|
+
(int)pos.y >= 0);
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
49
|
-
|
71
|
+
public static void deletRow(int y)
|
72
|
+
|
73
|
+
{
|
74
|
+
|
75
|
+
for (int x = 0; x < w; ++x)
|
50
76
|
|
51
77
|
{
|
52
78
|
|
53
|
-
|
54
|
-
|
55
|
-
//Random Index
|
56
|
-
|
57
|
-
|
79
|
+
PhotonNetwork.Destroy(grid[x, y].gameObject);
|
58
80
|
|
59
81
|
|
60
82
|
|
61
|
-
//Spawn Group at current Position
|
62
|
-
|
63
|
-
PhotonNetwork.Instantiate("I",
|
64
|
-
|
65
|
-
|
83
|
+
grid[x, y] = null;
|
66
84
|
|
67
85
|
}
|
68
86
|
|
69
87
|
}
|
70
88
|
|
71
|
-
_______________________
|
72
89
|
|
73
|
-
public class Group1 : Photon.MonoBehaviour
|
74
90
|
|
91
|
+
public static void decreaseRow(int y)
|
92
|
+
|
75
|
-
{
|
93
|
+
{
|
94
|
+
|
95
|
+
for (int x = 0; x < w; ++x)
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
if (grid[x, y] != null)
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
grid[x, y - 1] = grid[x, y];
|
104
|
+
|
105
|
+
grid[x, y] = null;
|
76
106
|
|
77
107
|
|
78
108
|
|
79
|
-
|
109
|
+
grid[x, y - 1].position += new Vector3(0, -1, 0);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
80
116
|
|
81
117
|
|
82
118
|
|
119
|
+
public static void decreaseRowAbove(int y)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
for (int i = y; i < h; ++i)
|
124
|
+
|
83
|
-
|
125
|
+
decreaseRow(i);
|
126
|
+
|
127
|
+
}
|
84
128
|
|
85
129
|
|
86
130
|
|
87
|
-
bool is
|
131
|
+
public static bool isRowFull(int y)
|
88
132
|
|
89
133
|
{
|
90
134
|
|
91
|
-
for
|
135
|
+
for (int x = 0; x < w; ++x)
|
92
136
|
|
93
|
-
{
|
94
|
-
|
95
|
-
Vector2 v = Grid1.roundVec2(child.position);
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
if (
|
137
|
+
if (grid[x, y] == null)
|
100
138
|
|
101
139
|
return false;
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
if (Grid1.grid[(int)v.x, (int)v.y] != null && Grid1.grid[(int)v.x, (int)v.y].parent != transform)
|
106
|
-
|
107
|
-
return false;
|
108
|
-
|
109
|
-
}
|
110
140
|
|
111
141
|
return true;
|
112
142
|
|
@@ -114,85 +144,41 @@
|
|
114
144
|
|
115
145
|
|
116
146
|
|
117
|
-
void
|
147
|
+
public static void deleteFullRoes()
|
118
148
|
|
119
149
|
{
|
120
150
|
|
121
|
-
for (int y = 0; y <
|
151
|
+
for (int y = 0; y < h; ++y)
|
122
|
-
|
123
|
-
for (int x = 0; x < Grid1.w; ++x)
|
124
|
-
|
125
|
-
if (Grid1.grid[x, y] != null) if (Grid1.grid[x, y].parent == transform)
|
126
|
-
|
127
|
-
Grid1.grid[x, y] = null;
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
foreach (Transform child in transform)
|
134
152
|
|
135
153
|
{
|
136
154
|
|
137
|
-
|
155
|
+
if (isRowFull(y))
|
138
156
|
|
157
|
+
{
|
158
|
+
|
159
|
+
deletRow(y);
|
160
|
+
|
139
|
-
|
161
|
+
decreaseRowAbove(y + 1);
|
162
|
+
|
163
|
+
--y;
|
164
|
+
|
165
|
+
}
|
140
166
|
|
141
167
|
}
|
142
168
|
|
143
169
|
}
|
144
170
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// Use this for initialization
|
158
|
-
|
159
|
-
void Start()
|
160
|
-
|
161
|
-
|
171
|
+
```
|
162
|
-
|
163
|
-
if (!isValidGridPos())
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
Debug.Log("Game Over");
|
168
|
-
|
169
|
-
PhotonNetwork.Destroy(gameObject);
|
170
|
-
|
171
|
-
AudioSource.Stop ();
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
172
|
|
193
173
|
###試したこと
|
194
174
|
|
175
|
+
```
|
176
|
+
|
195
|
-
|
177
|
+
DeleteRow()内でオブジェクトを削除する処理の前にPhotonNetworkを付けてみましたが、相手側の画面でオブジェクトが削除されません。
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
196
182
|
|
197
183
|
|
198
184
|
|