forked from walterellisfun/ConeCast
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhysics2DConesExample.cs
43 lines (32 loc) · 1.09 KB
/
Physics2DConesExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
public class ConeCast2DExample : MonoBehaviour {
public float radius;
public float depth;
public float angle;
private Physics physics;
void FixedUpdate ()
{
RaycastHit2D[] coneHits = Physics2DCones.ConeCastAll(transform.position, transform.forward, angle, depth);
for (int i = 0; i < coneHits.Length; i++)
{
//do something with collider information
coneHits[i].collider.gameObject.GetComponent<Renderer>().material.color = new Color(0, 0, 1f);
}
}
}
public class ConeCast2DExample2 : MonoBehaviour
{
public float radius;
public float depth;
public float angle;
private RayCastHit2D[] hits = new RayCastHit2D[100];
void FixedUpdate()
{
int numResults = Physics2DCones.ConeCastNonAlloc(transform.position, radius, transform.forward, hits, depth);
for (int i = 0; i < numResults; i++)
{
//do something with collider information
hits[i].collider.gameObject.GetComponent<Renderer>().material.color = new Color(0, 0, 1f);
}
}
}