diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /ProjectileHit.cs |
+init
Diffstat (limited to 'ProjectileHit.cs')
-rw-r--r-- | ProjectileHit.cs | 75 |
1 files changed, 75 insertions, 0 deletions
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<Player>(); + 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<Damagable>(); + 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<SFXPlayer>().Play(hit); + Object.Destroy(base.gameObject); + } +} |