-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProximityBomb.js
45 lines (37 loc) · 980 Bytes
/
ProximityBomb.js
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
#pragma strict
var BombMesh : GameObject;
var detonationRange : float = 3000;
var target : Transform;
var ExplosionObject : GameObject;
var alreadyExploded : boolean = false;
var PlayerLayer : int;
function Start() {
PlayerLayer = LayerMask.NameToLayer("PlayerLayer");
}
function Update() {
if (alreadyExploded == false) {
if (target == null) {TargetSearch();}
else {TryExploding();}
}
}
function TargetSearch() {
var colliders : Collider[] = Physics.OverlapSphere (transform.position, detonationRange);
for (var hit : Collider in colliders) {
if (hit && hit.gameObject.tag == "Player" && hit.gameObject.layer == PlayerLayer) {
target = hit.transform;
}
}
}
function TryExploding () {
if (alreadyExploded == false) {Explode();}
else return;
}
function Explode () {
if (ExplosionObject == null) {return;}
else {
alreadyExploded = true;
ExplosionObject.SetActive(true);
ExplosionObject.transform.parent = null;
BombMesh.SetActive(false);
}
}