diff options
| author | chai <215380520@qq.com> | 2024-05-19 16:05:01 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-19 16:05:01 +0800 |
| commit | c5f145786f4c6d2fe4bea831dfc16e52228920a5 (patch) | |
| tree | a6ead7ea8266c767d58ed0f816dcd7a1dd75bd65 /Thronefall_1_0/GameCode/LaunchableProjectile.cs | |
| parent | 48b64e573a1709dc923cb9162b55be0246b3ff63 (diff) | |
* move
Diffstat (limited to 'Thronefall_1_0/GameCode/LaunchableProjectile.cs')
| -rw-r--r-- | Thronefall_1_0/GameCode/LaunchableProjectile.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Thronefall_1_0/GameCode/LaunchableProjectile.cs b/Thronefall_1_0/GameCode/LaunchableProjectile.cs new file mode 100644 index 0000000..84f9fbd --- /dev/null +++ b/Thronefall_1_0/GameCode/LaunchableProjectile.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using UnityEngine; + +public class LaunchableProjectile : MonoBehaviour +{ + public float speed = 20f; + + public float lifetime = 3f; + + public bool groundedTranslation; + + public LayerMask groundLayer; + + public Vector3 groundingOfffset; + + public List<DamageModifyer> dmgModifiers = new List<DamageModifyer>(); + + public LayerMask hitLayer; + + public Vector3 damageBoxExtents; + + private bool launched; + + private float timer; + + private List<Hp> touchedEnemies = new List<Hp>(); + + public void Launch() + { + launched = true; + if (groundedTranslation && Physics.Raycast(new Ray(base.transform.position, Vector3.down), out var hitInfo, float.PositiveInfinity, groundLayer)) + { + base.transform.position = hitInfo.point + groundingOfffset; + } + } + + private void Update() + { + if (!launched) + { + return; + } + timer += Time.deltaTime; + base.transform.position += base.transform.forward * speed * Time.deltaTime; + Collider[] array = Physics.OverlapBox(base.transform.position, damageBoxExtents / 2f, base.transform.rotation, hitLayer); + for (int i = 0; i < array.Length; i++) + { + Hp componentInParent = array[i].GetComponentInParent<Hp>(); + if ((bool)componentInParent && !touchedEnemies.Contains(componentInParent)) + { + touchedEnemies.Add(componentInParent); + componentInParent.TakeDamage(DamageModifyer.CalculateDamageOnTarget(componentInParent.TaggedObj, dmgModifiers)); + } + } + if (timer >= lifetime) + { + Object.Destroy(base.gameObject); + } + } + + private void OnDrawGizmos() + { + Gizmos.color = Color.magenta; + Gizmos.DrawWireCube(base.transform.position, damageBoxExtents); + } +} |
