質問編集履歴
1
オブジェクトを削除しているコードを記載しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
+
|
2
3
|
UnityとPhotonを用いて通信対戦型のテトリスを作成しています。
|
3
4
|
ブロックの移動・回転を同期することはできましたが、一列揃った時自分の画面ではブロックが一列消えても相手画面では消えない状態です。
|
4
5
|
どのようにして相手画面のブロックを消せばよいでしょうか。 
|
@@ -10,92 +11,84 @@
|
|
10
11
|
```
|
11
12
|
|
12
13
|
###該当のソースコード
|
13
|
-
C#
|
14
14
|
|
15
|
+
```C#
|
15
|
-
public class
|
16
|
+
public class Grid1: Photon.PunBehaviour
|
16
17
|
{
|
17
18
|
|
18
|
-
public
|
19
|
+
public static int w = 10;
|
20
|
+
public static int h = 20;
|
21
|
+
public static Transform[,] grid = new Transform[w, h];
|
19
22
|
|
20
23
|
|
24
|
+
public static Vector2 roundVec2(Vector2 v)
|
25
|
+
{
|
26
|
+
return new Vector2(Mathf.Round(v.x), Mathf.Round(v.y));
|
27
|
+
}
|
21
28
|
|
22
|
-
public
|
29
|
+
public static bool insideBorder(Vector2 pos)
|
23
30
|
{
|
31
|
+
return ((int)pos.x >= 0 &&
|
32
|
+
(int)pos.x < w &&
|
33
|
+
(int)pos.y >= 0);
|
34
|
+
}
|
24
35
|
|
25
|
-
|
36
|
+
public static void deletRow(int y)
|
37
|
+
{
|
38
|
+
for (int x = 0; x < w; ++x)
|
26
39
|
{
|
40
|
+
PhotonNetwork.Destroy(grid[x, y].gameObject);
|
27
41
|
|
28
|
-
|
42
|
+
grid[x, y] = null;
|
29
|
-
int i = Random.Range(0, groups.Length);
|
30
|
-
|
31
|
-
//Spawn Group at current Position
|
32
|
-
PhotonNetwork.Instantiate("I",
|
33
|
-
transform.position, Quaternion.identity, 0);
|
34
43
|
}
|
35
44
|
}
|
36
|
-
_______________________
|
37
|
-
public class Group1 : Photon.MonoBehaviour
|
38
|
-
{
|
39
45
|
|
40
|
-
|
46
|
+
public static void decreaseRow(int y)
|
41
|
-
|
42
|
-
float lastFall = 0;
|
43
|
-
|
44
|
-
bool isValidGridPos()
|
45
47
|
{
|
46
|
-
|
48
|
+
for (int x = 0; x < w; ++x)
|
47
49
|
{
|
50
|
+
if (grid[x, y] != null)
|
51
|
+
{
|
48
|
-
|
52
|
+
grid[x, y - 1] = grid[x, y];
|
53
|
+
grid[x, y] = null;
|
49
54
|
|
50
|
-
|
55
|
+
grid[x, y - 1].position += new Vector3(0, -1, 0);
|
51
|
-
|
56
|
+
}
|
52
|
-
|
53
|
-
if (Grid1.grid[(int)v.x, (int)v.y] != null && Grid1.grid[(int)v.x, (int)v.y].parent != transform)
|
54
|
-
return false;
|
55
57
|
}
|
56
|
-
return true;
|
57
58
|
}
|
58
59
|
|
59
|
-
void
|
60
|
+
public static void decreaseRowAbove(int y)
|
60
61
|
{
|
61
|
-
for (int
|
62
|
+
for (int i = y; i < h; ++i)
|
62
|
-
for (int x = 0; x < Grid1.w; ++x)
|
63
|
-
if (Grid1.grid[x, y] != null) if (Grid1.grid[x, y].parent == transform)
|
64
|
-
|
63
|
+
decreaseRow(i);
|
64
|
+
}
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
public static bool isRowFull(int y)
|
68
|
-
|
67
|
+
{
|
69
|
-
|
68
|
+
for (int x = 0; x < w; ++x)
|
70
|
-
|
69
|
+
if (grid[x, y] == null)
|
70
|
+
return false;
|
71
|
-
|
71
|
+
return true;
|
72
72
|
}
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
public static void deleteFullRoes()
|
80
|
-
void Start()
|
81
|
-
|
75
|
+
{
|
82
|
-
|
76
|
+
for (int y = 0; y < h; ++y)
|
83
77
|
{
|
84
|
-
|
78
|
+
if (isRowFull(y))
|
79
|
+
{
|
85
|
-
|
80
|
+
deletRow(y);
|
86
|
-
|
81
|
+
decreaseRowAbove(y + 1);
|
82
|
+
--y;
|
83
|
+
}
|
87
84
|
}
|
88
85
|
}
|
86
|
+
```
|
87
|
+
###試したこと
|
88
|
+
```
|
89
|
+
DeleteRow()内でオブジェクトを削除する処理の前にPhotonNetworkを付けてみましたが、相手側の画面でオブジェクトが削除されません。
|
90
|
+
```
|
89
91
|
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
###試したこと
|
98
|
-
Group1の中のStart()内で、PhotonNetwork.Destroy(gameObject);を入れてみましたが消えませんでした。
|
99
|
-
|
100
93
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
101
94
|
より詳細な情報
|