-
Notifications
You must be signed in to change notification settings - Fork 0
/
Radar.cs
82 lines (69 loc) · 2.46 KB
/
Radar.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LoneX.TchilaVirus
{
public class Radar : MonoBehaviour
{
public WarningSign warning;
public Team targetTeam;
public Collider2D[] detectedEntities;
public new Collider2D collider;
void Awake()
{
warning.gameObject.SetActive(false);
}
public void OnTriggerEnter2D(Collider2D _other)
{
PlayerManager _detectedPlayer = _other.GetComponentInParent<PlayerManager>();
if( _detectedPlayer != null )
{
if(_detectedPlayer.team == targetTeam)
{
float _distance = (this.transform.position - _detectedPlayer.transform.position).magnitude;
warning.gameObject.SetActive(true);
}
}
}
public void OnTriggerStay2D(Collider2D _other)
{
detectedEntities = new Collider2D[5];
Physics2D.GetContacts(this.collider , detectedEntities);
PlayerManager _detectedPlayer = _other.GetComponentInParent<PlayerManager>();
if( _detectedPlayer != null )
{
if(_detectedPlayer.team == targetTeam)
{
float _distance = (this.transform.position - _detectedPlayer.transform.position).magnitude;
WarnPlayer(_distance);
}
}
}
public void OnTriggerExit2D(Collider2D _other)
{
PlayerManager _detectedPlayer = _other.GetComponentInParent<PlayerManager>();
if( _detectedPlayer != null )
{
if(_detectedPlayer.team == targetTeam)
{
float _distance = (this.transform.position - _detectedPlayer.transform.position).magnitude;
warning.gameObject.SetActive(false);
}
}
}
public void WarnPlayer(float _distance)
{
warning.gameObject.SetActive(true);
float _r = GetComponent<CircleCollider2D>().radius;
if(_distance < _r)
{
float _animationSpeed = 1 / ((0.9f/ _r) * _distance + 0.1f);
warning.SetAnimationSpeed(_animationSpeed);
}
else
{
warning.SetAnimationSpeed(-1f);
}
}
}
}