private void NormalDamage(Collision collision) { DamagePack damagePack = new DamagePack(); damagePack.Damage = Damage; damagePack.Owner = Owner; collision.gameObject.SendMessage("ApplyDamage", damagePack, SendMessageOptions.DontRequireReceiver); }
public virtual void ApplyDamage(DamagePack damage) { if (HP < 0) { return; } LatestHit = damage.Owner; HP -= damage.Damage; if (HP <= 0) { Dead(); } }
private void ExplosionDamage() { Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius); for (int i = 0; i < hitColliders.Length; i++) { Collider hit = hitColliders[i]; if (!hit) { continue; } if (hit.GetComponent <Rigidbody>()) { hit.GetComponent <Rigidbody>().AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius, 3.0f); } } Collider[] dmhitColliders = Physics.OverlapSphere(transform.position, DamageRadius); for (int i = 0; i < dmhitColliders.Length; i++) { Collider hit = dmhitColliders[i]; if (!hit) { continue; } if (DoDamageCheck(hit.gameObject) && (Owner == null || (Owner != null && hit.gameObject != Owner.gameObject))) { DamagePack damagePack = new DamagePack(); damagePack.Damage = Damage; damagePack.Owner = Owner; hit.gameObject.SendMessage("ApplyDamage", damagePack, SendMessageOptions.DontRequireReceiver); } } }
void ShootRay() { if (GetComponent <Collider> ()) { Physics.IgnoreCollision(GetComponent <Collider> (), Owner.GetComponent <Collider> ()); if (Owner.transform.root) { foreach (Collider col in Owner.transform.root.GetComponentsInChildren <Collider>()) { Physics.IgnoreCollision(GetComponent <Collider> (), col); } } } RaycastHit hit; GameObject explosion = null; if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range)) { AimPoint = hit.point; if (Explosion != null) { if (WeaponSystem.Pool != null) { explosion = WeaponSystem.Pool.Instantiate(Explosion, AimPoint, this.transform.rotation); } else { explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, this.transform.rotation); } } DamagePack damagePack = new DamagePack(); damagePack.Damage = Damage; damagePack.Owner = Owner; hit.collider.gameObject.SendMessage("ApplyDamage", damagePack, SendMessageOptions.DontRequireReceiver); } else { AimPoint = this.transform.position + this.transform.forward * Range; if (Explosion != null) { if (WeaponSystem.Pool != null) { explosion = WeaponSystem.Pool.Instantiate(Explosion, AimPoint, this.transform.rotation); } else { explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, this.transform.rotation); } } } if (explosion) { explosion.transform.forward = this.transform.forward; DamageBase dmg = explosion.GetComponent <DamageBase> (); if (dmg) { dmg.TargetTag = TargetTag; } } if (Trail) { Trail.SetPosition(0, this.transform.position); Trail.SetPosition(1, AimPoint); } if (WeaponSystem.Pool == null) { Destroy(this.gameObject, LifeTime); } }