/
RadarPing.cs
56 lines (46 loc) · 1.02 KB
/
RadarPing.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
44
45
46
47
48
49
50
51
52
53
54
55
56
using C5;
using UnityEngine;
using UnitySteer.Helpers;
/// <summary>
/// Detects neighbors by pinging an area with Physics.OverlapSphere
/// </summary>
public class RadarPing: Radar
{
#region Private properties
[SerializeField]
private float _detectionRadius = 10;
[SerializeField]
private bool _drawGizmos = false;
#endregion
#region Public properties
/// <summary>
/// Radar ping detection radius
/// </summary>
public float DetectionRadius {
get {
return this._detectionRadius;
}
set {
_detectionRadius = value;
}
}
#endregion
#region Methods
void OnDrawGizmos()
{
if (_drawGizmos)
{
var pos = (Vehicle == null) ? transform.position : Vehicle.Position;
Gizmos.color = Color.cyan;
Gizmos.DrawWireSphere(pos, _detectionRadius);
}
}
protected override IList<Collider> Detect()
{
var detected = Physics.OverlapSphere(Vehicle.Position, _detectionRadius, LayersChecked);
var list = new ArrayList<Collider>();
list.AddAll<Collider>(detected);
return list;
}
#endregion
}