forked from walterellisfun/ConeCast
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhysicsConesExample.cs
40 lines (30 loc) · 1.05 KB
/
PhysicsConesExample.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
using UnityEngine;
public class ConeCastExample : MonoBehaviour {
public float radius;
public float depth;
public float angle;
void FixedUpdate () {
RaycastHit[] coneHits = PhysicsCones.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 ConeCastExample2 : MonoBehaviour
{
public float radius;
public float depth;
public float angle;
private RayCastHit[] hits = new RayCastHit[100];
void FixedUpdate()
{
int numResults = PhysicsCones.ConeCastNonAlloc(transform.position, radius, transform.forward, hits, depth);
for (int i = 0; i < hits.Length; i++)
{
//do something with collider information
hits[i].collider.gameObject.GetComponent<Renderer>().material.color = new Color(0, 0, 1f);
}
}
}