回答編集履歴
2
サンプルコードの追加
test
CHANGED
@@ -15,3 +15,53 @@
|
|
15
15
|
下記リンクを参考にPhysics2D.BoxCastを試してみてください
|
16
16
|
|
17
17
|
[参考リンク](http://kan-kikuchi.hatenablog.com/entry/RayCast4)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
## サンプルの追記
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```csharp
|
26
|
+
|
27
|
+
public class RaycastTest : MonoBehaviour
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
void Update()
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
//現在の位置から X5 Y5のサイズをBOXを下(0, -1)方向にBoxCastする
|
36
|
+
|
37
|
+
var result = Physics2D.BoxCast(transform.position, new Vector2(5, 5), 0f, new Vector2(0, -1));
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
//なにかと衝突した時だけそのオブジェクトの名前をログに出す
|
42
|
+
|
43
|
+
if (result.collider)
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
Debug.Log(result.collider.gameObject.name);
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+

|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
1. スクリプトをRaycastStartPositionにアタッチ
|
66
|
+
|
67
|
+
2. RaycastTargetには適切な2D Colliderをアタッチしておく
|
1
Physics2DでのRaycastの例を追記
test
CHANGED
@@ -5,3 +5,13 @@
|
|
5
5
|
Physics.BoxCastを使用して上から下に向かってRayCastをし当たったポイントを現時点での最高高度として取得するのはどうでしょうか
|
6
6
|
|
7
7
|
[https://teratail.com/questions/123603](https://teratail.com/questions/123603)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
## 追記
|
12
|
+
|
13
|
+
Unity2Dというのを見落としていました
|
14
|
+
|
15
|
+
下記リンクを参考にPhysics2D.BoxCastを試してみてください
|
16
|
+
|
17
|
+
[参考リンク](http://kan-kikuchi.hatenablog.com/entry/RayCast4)
|