blob: 54220168f5da1cb7a8db9f9254701c60f641d5fe (
plain)
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
|
using System.Collections;
using UnityEngine;
public class Landmine : Projectile
{
public float blastRadius = 0.5f;
private bool armed;
[SerializeField]
private GameObject explosion;
protected override void Start()
{
base.Start();
SpawnManager.instance.destroyOnNewLevel.Add(base.gameObject);
}
public void SetEndPosition(Vector3 endPos)
{
StartCoroutine(ThrowMine(endPos));
}
protected override void FixedUpdate()
{
}
private void OnTriggerEnter(Collider other)
{
if (armed && other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
{
Explode();
}
}
private void Explode()
{
Collider[] array = Physics.OverlapSphere(base.transform.position, blastRadius, layermask, QueryTriggerInteraction.Collide);
for (int i = 0; i < array.Length; i++)
{
IDamageable component = array[i].GetComponent<IDamageable>();
if (component != null)
{
DealDamage(component);
}
}
Object.Instantiate(explosion, base.transform.position, Quaternion.identity).transform.localScale = Vector3.one * 0.5f;
SpawnManager.instance.destroyOnNewLevel.Remove(base.gameObject);
Object.Destroy(base.gameObject);
}
private IEnumerator ThrowMine(Vector3 endPos)
{
Vector3 direction = endPos - base.transform.position;
float throwTime = 1f;
base.transform.localScale = Vector3.zero;
for (float i = 0f; i < 1f; i += Time.deltaTime / throwTime)
{
base.transform.localScale = Vector3.one * i;
base.transform.Translate(direction * Time.deltaTime / throwTime);
yield return null;
}
base.transform.localScale = Vector3.one;
base.transform.position = endPos;
armed = true;
}
}
|