回答編集履歴
1
コードの追記
test
CHANGED
@@ -3,3 +3,111 @@
|
|
3
3
|
四方向に当たり判定を得るためのオブジェクトを配置し
|
4
4
|
|
5
5
|
それぞれの当たり判定を確認するというのはどうでしょうか
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
4方向の当たり判定を確認するコードファイル名がcol.cs
|
10
|
+
|
11
|
+
かつ親オブジェクトに適応されており、
|
12
|
+
|
13
|
+
子オブジェクト名をcol_1~4 の連番とした時
|
14
|
+
|
15
|
+
さらに親オブジェクト名がplayerである時
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
子オブジェクトコード
|
20
|
+
|
21
|
+
```c#
|
22
|
+
|
23
|
+
private col cols;
|
24
|
+
|
25
|
+
private int select;
|
26
|
+
|
27
|
+
private GameObject parent;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
void Start(){
|
32
|
+
|
33
|
+
select = ((int)gameObhect.name.Replace("col_","") -1);
|
34
|
+
|
35
|
+
parent = GameObject.Find("player");
|
36
|
+
|
37
|
+
cols = parent.GetCompornent<col>();
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
void OnTriggerEnter(Collider other) {
|
44
|
+
|
45
|
+
if (parent != other.gameObject){
|
46
|
+
|
47
|
+
cols[select] = true;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
void OnTriggerExit(Collider other) {
|
54
|
+
|
55
|
+
if (parent != other.gameObject){
|
56
|
+
|
57
|
+
cols[select] = false;
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
親オブジェクト
|
68
|
+
|
69
|
+
```c#
|
70
|
+
|
71
|
+
private bool[] cols = new bool[4];
|
72
|
+
|
73
|
+
private bool col = false;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
void Update(){
|
78
|
+
|
79
|
+
var count = 0;
|
80
|
+
|
81
|
+
for(var i = 0; i< cols.Length; i++){
|
82
|
+
|
83
|
+
if(!cols[i]){
|
84
|
+
|
85
|
+
break;
|
86
|
+
|
87
|
+
} else {
|
88
|
+
|
89
|
+
count++;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
if(count == cols.Length){
|
96
|
+
|
97
|
+
col = true;
|
98
|
+
|
99
|
+
Debug.Log("全部true");
|
100
|
+
|
101
|
+
} else {
|
102
|
+
|
103
|
+
col = false;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
動作テストしてないのでケアレスミスがあるかもしれませんが
|
112
|
+
|
113
|
+
こんな感じのコードで実現可能かと思います。
|