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 /GameCode/AutoAttack.cs | |
| parent | 48b64e573a1709dc923cb9162b55be0246b3ff63 (diff) | |
* move
Diffstat (limited to 'GameCode/AutoAttack.cs')
| -rw-r--r-- | GameCode/AutoAttack.cs | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/GameCode/AutoAttack.cs b/GameCode/AutoAttack.cs deleted file mode 100644 index 71d1aec..0000000 --- a/GameCode/AutoAttack.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Events; - -public class AutoAttack : MonoBehaviour -{ - public float cooldownDuration = 1f; - - public float cooldownAfterSpawn = -1f; - - [Range(0f, 1f)] - public float cooldownRandomization; - - [Tooltip("How often this script checks if an attack is possible once the cooldown is down")] - public float recheckTargetInterval = 0.5f; - - public List<TargetPriority> targetPriorities = new List<TargetPriority>(); - - public Weapon weapon; - - public float spawnAttackHeight = 0.5f; - - private TaggedObject taggedObject; - - private float cooldown = -1f; - - private bool onCooldown; - - [Tooltip("While the getDisabledBy auto attack script is on cooldown, this auto attack script here can't attack.")] - public AutoAttack getsDisaledBy; - - private float damageMultiplyer = 1f; - - [HideInInspector] - public UnityEvent onAttackTriggered = new UnityEvent(); - - private Vector3 lastTargetPosition; - - public float DamageMultiplyer - { - get - { - return damageMultiplyer; - } - set - { - damageMultiplyer = value; - } - } - - public Vector3 LastTargetPosition => lastTargetPosition; - - public void ReduceCooldownBy(float _reduceBy) - { - cooldown -= _reduceBy; - } - - private void Start() - { - cooldown = cooldownAfterSpawn; - taggedObject = GetComponent<TaggedObject>(); - } - - private void Update() - { - bool flag = true; - if (getsDisaledBy != null && getsDisaledBy.onCooldown) - { - flag = false; - cooldown += Time.deltaTime; - } - cooldown -= Time.deltaTime; - if (cooldown <= 0f && flag) - { - TaggedObject taggedObject = FindAutoAttackTarget(); - if (taggedObject == null) - { - cooldown += recheckTargetInterval; - onCooldown = false; - return; - } - cooldown += cooldownDuration * (1f + (1f - 2f * Random.value) * cooldownRandomization); - weapon.Attack(base.transform.position + spawnAttackHeight * Vector3.up, taggedObject.Hp, Vector3.zero, this.taggedObject, damageMultiplyer); - lastTargetPosition = taggedObject.transform.position; - onAttackTriggered.Invoke(); - onCooldown = true; - } - } - - public virtual TaggedObject FindAutoAttackTarget() - { - for (int i = 0; i < targetPriorities.Count; i++) - { - TaggedObject taggedObject = targetPriorities[i].FindClosestTaggedObject(base.transform.position); - if (taggedObject != null) - { - return taggedObject; - } - } - return null; - } -} |
