teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

オブジェクトを削除しているコードを記載しました。

2017/11/02 03:09

投稿

MasakiMarugame
MasakiMarugame

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,5 @@
1
1
  ###前提・実現したいこと
2
+
2
3
   UnityとPhotonを用いて通信対戦型のテトリスを作成しています。
3
4
  ブロックの移動・回転を同期することはできましたが、一列揃った時自分の画面ではブロックが一列消えても相手画面では消えない状態です。
4
5
  どのようにして相手画面のブロックを消せばよいでしょうか。 ![イメージ説明](258f4456bec24802ea67d97c0693327b.png)
@@ -10,92 +11,84 @@
10
11
  ```
11
12
 
12
13
  ###該当のソースコード
13
- C#
14
14
 
15
+ ```C#
15
- public class Spawner1 :Photon.MonoBehaviour
16
+ public class Grid1: Photon.PunBehaviour
16
17
  {
17
18
 
18
- public GameObject[] groups;
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 void spawnNext()
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
- if (PhotonNetwork.isMasterClient)
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
- //Random Index
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
- public AudioSource AudioSource;
46
+ public static void decreaseRow(int y)
41
-
42
- float lastFall = 0;
43
-
44
- bool isValidGridPos()
45
47
  {
46
- foreach (Transform child in transform)
48
+ for (int x = 0; x < w; ++x)
47
49
  {
50
+ if (grid[x, y] != null)
51
+ {
48
- Vector2 v = Grid1.roundVec2(child.position);
52
+ grid[x, y - 1] = grid[x, y];
53
+ grid[x, y] = null;
49
54
 
50
- if (!Grid1.insideBorder(v))
55
+ grid[x, y - 1].position += new Vector3(0, -1, 0);
51
- return false;
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 updateGrid()
60
+ public static void decreaseRowAbove(int y)
60
61
  {
61
- for (int y = 0; y < Grid1.h; ++y)
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
- Grid1.grid[x, y] = null;
63
+ decreaseRow(i);
64
+ }
65
65
 
66
-
67
- foreach (Transform child in transform)
66
+ public static bool isRowFull(int y)
68
- {
67
+ {
69
- Vector2 v = Grid1.roundVec2(child.position);
68
+ for (int x = 0; x < w; ++x)
70
- Grid1.grid[(int)v.x, (int)v.y] = child;
69
+ if (grid[x, y] == null)
70
+ return false;
71
- }
71
+ return true;
72
72
  }
73
73
 
74
-
75
-
76
-
77
-
78
-
79
- // Use this for initialization
74
+ public static void deleteFullRoes()
80
- void Start()
81
- {
75
+ {
82
- if (!isValidGridPos())
76
+ for (int y = 0; y < h; ++y)
83
77
  {
84
- Debug.Log("Game Over");
78
+ if (isRowFull(y))
79
+ {
85
- PhotonNetwork.Destroy(gameObject);
80
+ deletRow(y);
86
- AudioSource.Stop ();
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
  より詳細な情報