質問編集履歴
4
いただいた修正案を元に修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
public Text RowCount;
|
14
14
|
public int deleteRowsCount = 0;
|
15
15
|
|
16
|
-
|
16
|
+
bool deleteFullRows()
|
17
17
|
{
|
18
18
|
for (int y = 0; y < Grid.h; ++y)
|
19
19
|
{
|
@@ -28,12 +28,11 @@
|
|
28
28
|
void Start () {
|
29
29
|
RowCount.text = "消えた列:" + deleteRowsCount;
|
30
30
|
}
|
31
|
-
|
32
|
-
// Update is called once per frame
|
33
|
-
|
31
|
+
public void countUp() {
|
34
32
|
if (deleteFullRows())
|
35
33
|
{
|
36
34
|
++deleteRowsCount;
|
35
|
+
RowCount.text = "消えた列:" + deleteRowsCount;
|
37
36
|
}
|
38
37
|
}
|
39
38
|
}
|
@@ -49,6 +48,7 @@
|
|
49
48
|
{
|
50
49
|
private Vector3 screenPoint;
|
51
50
|
private Vector3 offset;
|
51
|
+
private Count count;
|
52
52
|
|
53
53
|
//座標が範囲内であるか,Gridに値があるかどうかを判定
|
54
54
|
bool isValidGridPos()
|
@@ -114,8 +114,8 @@
|
|
114
114
|
if (isValidGridPos())
|
115
115
|
{
|
116
116
|
transform.position = Grid.roundVec2(currentPosition);
|
117
|
-
//
|
117
|
+
//修正
|
118
|
-
|
118
|
+
count.countUp();
|
119
119
|
//横列と縦列を消去
|
120
120
|
Grid.deleteFullRows();
|
121
121
|
Grid.deleteFullLines();
|
@@ -141,7 +141,7 @@
|
|
141
141
|
// Use this for initialization
|
142
142
|
void Start()
|
143
143
|
{
|
144
|
-
|
144
|
+
count = FindObjectOfType<Count>();
|
145
145
|
}
|
146
146
|
|
147
147
|
// Update is called once per frame
|
3
コードを変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
public Text RowCount;
|
14
14
|
public int deleteRowsCount = 0;
|
15
15
|
|
16
|
-
bool deleteFullRows()
|
16
|
+
public static bool deleteFullRows()
|
17
17
|
{
|
18
18
|
for (int y = 0; y < Grid.h; ++y)
|
19
19
|
{
|
@@ -114,6 +114,8 @@
|
|
114
114
|
if (isValidGridPos())
|
115
115
|
{
|
116
116
|
transform.position = Grid.roundVec2(currentPosition);
|
117
|
+
//追加
|
118
|
+
Count.deleteFullRows();
|
117
119
|
//横列と縦列を消去
|
118
120
|
Grid.deleteFullRows();
|
119
121
|
Grid.deleteFullLines();
|
2
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -114,6 +114,7 @@
|
|
114
114
|
if (isValidGridPos())
|
115
115
|
{
|
116
116
|
transform.position = Grid.roundVec2(currentPosition);
|
117
|
+
//横列と縦列を消去
|
117
118
|
Grid.deleteFullRows();
|
118
119
|
Grid.deleteFullLines();
|
119
120
|
|
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,7 +39,125 @@
|
|
39
39
|
}
|
40
40
|
|
41
41
|
```
|
42
|
+
Group.cs
|
43
|
+
```C#
|
44
|
+
using System.Collections;
|
45
|
+
using System.Collections.Generic;
|
46
|
+
using UnityEngine;
|
42
47
|
|
48
|
+
public class Group : MonoBehaviour
|
49
|
+
{
|
50
|
+
private Vector3 screenPoint;
|
51
|
+
private Vector3 offset;
|
52
|
+
|
53
|
+
//座標が範囲内であるか,Gridに値があるかどうかを判定
|
54
|
+
bool isValidGridPos()
|
55
|
+
{
|
56
|
+
foreach (Transform child in transform)
|
57
|
+
{
|
58
|
+
Vector2 v = Grid.roundVec2(child.position);
|
59
|
+
|
60
|
+
if (!Grid.insideBorder(v))
|
61
|
+
return false;
|
62
|
+
|
63
|
+
if (Grid.grid[(int)v.x, (int)v.y] != null &&
|
64
|
+
Grid.grid[(int)v.x, (int)v.y].parent != transform)
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
return true;
|
68
|
+
}
|
69
|
+
|
70
|
+
void updateGrid()
|
71
|
+
{
|
72
|
+
for (int y = 0; y < Grid.h; ++y)
|
73
|
+
for (int x = 0; x < Grid.w; ++x)
|
74
|
+
if (Grid.grid[x, y] != null)
|
75
|
+
if (Grid.grid[x, y].parent == transform)
|
76
|
+
Grid.grid[x, y] = null;
|
77
|
+
|
78
|
+
foreach (Transform child in transform)
|
79
|
+
{
|
80
|
+
Vector2 v = Grid.roundVec2(child.position);
|
81
|
+
Grid.grid[(int)v.x, (int)v.y] = child;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
//オブジェクトをクリックする
|
86
|
+
void OnMouseDown()
|
87
|
+
{
|
88
|
+
// マウスカーソルは、スクリーン座標なので、
|
89
|
+
// 対象のオブジェクトもスクリーン座標に変換してから計算する。
|
90
|
+
|
91
|
+
// このオブジェクトの位置(transform.position)をスクリーン座標に変換。
|
92
|
+
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
|
93
|
+
// ワールド座標上の、マウスカーソルと、対象の位置の差分。
|
94
|
+
offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
//オブジェクトをドラッグする
|
100
|
+
void OnMouseDrag()
|
101
|
+
{
|
102
|
+
Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
|
103
|
+
Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + this.offset;
|
104
|
+
transform.position = currentPosition;
|
105
|
+
}
|
106
|
+
|
107
|
+
//オブジェクトをドロップする
|
108
|
+
void OnMouseUp()
|
109
|
+
{
|
110
|
+
Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
|
111
|
+
Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + this.offset;
|
112
|
+
|
113
|
+
//currentPositionが範囲内であるか,Gridに値があるかどうかを判定
|
114
|
+
if (isValidGridPos())
|
115
|
+
{
|
116
|
+
transform.position = Grid.roundVec2(currentPosition);
|
117
|
+
Grid.deleteFullRows();
|
118
|
+
Grid.deleteFullLines();
|
119
|
+
|
120
|
+
//指定範囲内ではブロックの当たり判定を無くす
|
121
|
+
BoxCollider2D collider = GetComponent<BoxCollider2D>();
|
122
|
+
collider.enabled = false;
|
123
|
+
|
124
|
+
//次のブロックを呼び出す
|
125
|
+
FindObjectOfType<Spawner>().spawnNext();
|
126
|
+
|
127
|
+
|
128
|
+
}
|
129
|
+
else
|
130
|
+
{
|
131
|
+
//Spawnerオブジェクトの座標を取る
|
132
|
+
transform.position = GameObject.Find("Spawner").transform.position;
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
// Use this for initialization
|
139
|
+
void Start()
|
140
|
+
{
|
141
|
+
|
142
|
+
}
|
143
|
+
|
144
|
+
// Update is called once per frame
|
145
|
+
void Update()
|
146
|
+
{
|
147
|
+
if (isValidGridPos())
|
148
|
+
{
|
149
|
+
// It's valid. Update grid.
|
150
|
+
updateGrid();
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|
160
|
+
|
43
161
|
Grid.cs
|
44
162
|
```C#
|
45
163
|
using System.Collections;
|