From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- ProjectileHit.cs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ProjectileHit.cs (limited to 'ProjectileHit.cs') diff --git a/ProjectileHit.cs b/ProjectileHit.cs new file mode 100644 index 0000000..305f9fc --- /dev/null +++ b/ProjectileHit.cs @@ -0,0 +1,75 @@ +using UnityEngine; + +public class ProjectileHit : MonoBehaviour +{ + public GameObject soundPlayer; + + public ProjectileHitSpawn[] objectsToSpawnOnHit; + + private bool done; + + public float damage = 25f; + + public float force; + + private void Start() + { + } + + private void Update() + { + } + + public void Hit(RaycastHit hit) + { + if (done) + { + return; + } + done = true; + Player component = hit.transform.root.GetComponent(); + ProjectileHitSpawn[] array = objectsToSpawnOnHit; + foreach (ProjectileHitSpawn projectileHitSpawn in array) + { + Vector3 point = hit.point; + Quaternion rotation = Quaternion.identity; + if ((bool)component) + { + if (projectileHitSpawn.playerSpawnRotation == ProjectileHitSpawn.SpawnRotation.forward) + { + rotation = Quaternion.LookRotation(base.transform.forward); + } + if (projectileHitSpawn.playerSpawnRotation == ProjectileHitSpawn.SpawnRotation.normal) + { + rotation = Quaternion.LookRotation(hit.normal); + } + } + else + { + if (projectileHitSpawn.groundSpawnRotation == ProjectileHitSpawn.SpawnRotation.forward) + { + rotation = Quaternion.LookRotation(base.transform.forward); + } + if (projectileHitSpawn.groundSpawnRotation == ProjectileHitSpawn.SpawnRotation.normal) + { + rotation = Quaternion.LookRotation(hit.normal); + } + } + GameObject gameObject = Object.Instantiate(projectileHitSpawn.spawnedObject, point, rotation); + } + Damagable component2 = hit.transform.GetComponent(); + if ((bool)component2) + { + component2.TakeDamage(damage * base.transform.forward, hit.point); + } + Rigidbody rigidbody = hit.rigidbody; + if ((bool)rigidbody && force != 0f) + { + float num = 1f; + num = Mathf.Clamp(rigidbody.mass / 10f, 0f, 1f); + rigidbody.AddForceAtPosition(base.transform.forward * force * num, hit.point, ForceMode.Impulse); + } + Object.Instantiate(soundPlayer, hit.point, Quaternion.identity).GetComponent().Play(hit); + Object.Destroy(base.gameObject); + } +} -- cgit v1.1-26-g67d0