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); } }