summaryrefslogtreecommitdiff
path: root/GameCode/ProjectileCollision.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/ProjectileCollision.cs
+ init
Diffstat (limited to 'GameCode/ProjectileCollision.cs')
-rw-r--r--GameCode/ProjectileCollision.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/GameCode/ProjectileCollision.cs b/GameCode/ProjectileCollision.cs
new file mode 100644
index 0000000..8833660
--- /dev/null
+++ b/GameCode/ProjectileCollision.cs
@@ -0,0 +1,86 @@
+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<ChildRPC>();
+ rpc.childRPCs.Add("KillBullet", Die);
+ reflect = GetComponentInParent<RayHitReflect>();
+ ProjectileHit componentInParent = GetComponentInParent<ProjectileHit>();
+ 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<ProjectileCollision>();
+ if ((bool)componentInChildren)
+ {
+ reflect = componentInChildren.GetComponentInParent<RayHitReflect>();
+ 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<ProjectileHit>().Hit(HitInfo.GetHitInfo(raycastHit2D), forceCall: true);
+ }
+ }
+}