-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShellExplosionScript.cs
90 lines (82 loc) · 2.71 KB
/
ShellExplosionScript.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
83
84
85
86
87
88
89
90
using UnityEngine;
using System.Collections;
public class ShellExplosionScript : MonoBehaviour
{
public LayerMask m_HitMask;
// public ParticleSystem m_ExplosionParticles;
// public AudioSource m_ExplosionAudio;
public float m_MaxDamage = 100f;
public float m_ExplosionForce = 1000f;
public float m_MaxLiftTime = 7f;
public float m_ExplosionRadius = 5f;
public float damageBooster = 1f;
void Start ()
{
Destroy (gameObject, m_MaxLiftTime);
}
private void OnTriggerEnter(Collider other)
{
Collider[] colliders = Physics.OverlapSphere (transform.position, m_ExplosionRadius, m_HitMask);
for(int i = 0; i < colliders.Length; i++)
{
Rigidbody targetRigidBody = colliders[i].GetComponentInParent<Rigidbody>();
if(!targetRigidBody)
{
continue;
}
targetRigidBody.AddExplosionForce (m_ExplosionForce, transform.position, m_ExplosionRadius);
float damage = CalculateDamage(targetRigidBody.position);
if (targetRigidBody == null)
{
BlockCharacterLife causeDDD = targetRigidBody.GetComponentInParent<BlockCharacterLife>();
if(causeDDD != null)
{
causeDDD.shots += (int)damage;
}
}
else
{
targetRigidBody.GetComponentInParent<Rigidbody> ().AddExplosionForce (m_ExplosionForce, transform.position, m_ExplosionRadius, 5.9f, ForceMode.Impulse);
CauseDamageDestroy causeDD = targetRigidBody.GetComponentInParent<CauseDamageDestroy>();
if(causeDD != null)
{
causeDD.shots += (int)damage;
}
BlockCharacterLife causeDDDD = targetRigidBody.GetComponentInParent<BlockCharacterLife>();
if(causeDDDD != null)
{
causeDDDD.shots += (int)damage;
}
BlockCharacterLife causeNinja = targetRigidBody.GetComponent<BlockCharacterLife>();
if(causeNinja != null)
{
causeNinja.shots += (int)damage;
}
PoppyLife popLife = targetRigidBody.GetComponent<PoppyLife> ();
if(popLife != null)
{
popLife.shots += (int)damage;
}
EnemyHealth1 enemyHealth = targetRigidBody.GetComponentInParent<EnemyHealth1> ();
if (enemyHealth != null)
{
enemyHealth.TakeDamage ((int)(damage * damageBooster), targetRigidBody.transform.position);
}
}
}
// m_ExplosionParticles.transform.transform.parent = null;
// m_ExplosionParticles.Play ();
// m_ExplosionAudio.Play ();
// Destroy (m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);
Destroy (gameObject);
}
private float CalculateDamage(Vector3 targetPosition)
{
Vector3 explosionToTarget = targetPosition - transform.position;
float dist = explosionToTarget.magnitude;
float relativeDist = (m_ExplosionRadius - dist) / m_ExplosionRadius;
float damage = relativeDist * m_MaxDamage;
damage = Mathf.Max (0f, damage);
return damage;
}
}