using UnityEngine; public class ProjectileCollision : ProjectileHitSurface { public bool scaleWithDMG; public float health; private float deathThreshold; private RayHitReflect reflect; private ChildRPC rpc; private float startDMG; private bool hasCollided; public GameObject sparkObject; private void Start() { rpc = GetComponentInParent(); rpc.childRPCs.Add("KillBullet", Die); reflect = GetComponentInParent(); ProjectileHit componentInParent = GetComponentInParent(); if (scaleWithDMG) { base.transform.localScale *= (componentInParent.damage / 55f + 1f) * 0.5f; health = componentInParent.damage; } startDMG = componentInParent.damage; deathThreshold = health * 0.1f; } public override HasToStop HitSurface(HitInfo hit, GameObject projectile) { if (Vector2.Angle(base.transform.root.forward, projectile.transform.forward) < 45f) { return HasToStop.HasToStop; } if ((bool)reflect && reflect.timeOfBounce + 0.5f > Time.time) { return HasToStop.HasToStop; } ProjectileCollision componentInChildren = projectile.GetComponentInChildren(); if ((bool)componentInChildren) { reflect = componentInChildren.GetComponentInParent(); if ((bool)reflect && reflect.timeOfBounce + 0.5f > Time.time) { return HasToStop.HasToStop; } float dmg = health; float dmg2 = componentInChildren.health; componentInChildren.TakeDamage(dmg); TakeDamage(dmg2); } return HasToStop.HasToStop; } public void TakeDamage(float dmg) { if (!hasCollided) { health -= dmg; if ((bool)rpc && health < deathThreshold) { rpc.CallFunction("KillBullet"); } } } public void Die() { if (!hasCollided) { hasCollided = true; RaycastHit2D raycastHit2D = default(RaycastHit2D); raycastHit2D.normal = -base.transform.root.forward; raycastHit2D.point = base.transform.position; Object.Instantiate(sparkObject, base.transform.position, base.transform.rotation).transform.localScale = Vector3.one * ((startDMG / 55f + 1f) * 0.5f); GetComponentInParent().Hit(HitInfo.GetHitInfo(raycastHit2D), forceCall: true); } } }