-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSonar.cs
More file actions
63 lines (46 loc) · 1.41 KB
/
Copy pathSonar.cs
File metadata and controls
63 lines (46 loc) · 1.41 KB
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
57
58
59
60
61
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace Robot
{
public class Sonar : MonoBehaviour
{
[SerializeField]
private float _viewRadious;
private string nameTasksObject = "TasksFolder";
private Dictionary<Transform, int> _objectsInSonarArea;
public Dictionary<Transform, int> objectsInSonarArea
{
get { return _objectsInSonarArea; }
}
public float viewRadious
{
get { return _viewRadious; }
}
private void Start()
{
Transform tasks = GameObject.FindWithTag(nameTasksObject).transform;
_objectsInSonarArea = new Dictionary<Transform, int>();
for (int ID = 0; ID < tasks.childCount; ID++)
{
_objectsInSonarArea.Add(tasks.GetChild(ID), 0);
}
}
void Update()
{
for (int i = 0; i < _objectsInSonarArea.Count; i++)
{
var element = _objectsInSonarArea.ElementAt(i);
if (Vector3.Distance(element.Key.position, transform.position) <= _viewRadious)
{
_objectsInSonarArea[element.Key] = 1;
}
else
{
_objectsInSonarArea[element.Key] = 0;
}
}
}
}
}