using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rider : Ally { [SerializeField] private GameObject _detection; [SerializeField] private GameObject _chargeDetection; private Detection _chargeDetectionScript; [SerializeField] private GameObject _root; private Root _rootScript; private Vector2 _movementVector = Vector2.zero; private bool _isCharging; [SerializeField] private int _maxChargeHitCount; private List _opponentsHit = new List(); [SerializeField] private int _maxChargeDistance; private Vector3 _originalPos; public override void Start() { base.Start(); _chargeDetectionScript = _chargeDetection.GetComponent(); _rootScript = _root.GetComponent(); _originalPos = transform.position; _isCharging = true; } public override void Update() { if (_isCharging) { _detection.SetActive(false); _chargeDetection.SetActive(true); // movement _movementVector.x = Time.deltaTime * Speed; transform.position += (Vector3)_movementVector; // attack if (IsEnemyDetected && !_opponentsHit.Contains(Enemy)) { AttackEnemyRiding(); } // reset if (transform.position.x - _originalPos.x >= _maxChargeDistance || _opponentsHit.Count >= _maxChargeHitCount) { _isCharging = false; _movementVector = Vector2.zero; transform.position = _originalPos; _opponentsHit.Clear(); IsEnemyDetected = false; Enemy = null; _detection.SetActive(true); _chargeDetection.SetActive(false); } } else { if (IsEnemyDetected) { AttackEnemy(); } } } void AttackEnemyRiding() { _rootScript.Attack(); _opponentsHit.Add(Enemy); } void AttackEnemy() { //Attack Cooldown if (AttackSpeedWait > AttackInterval) { Animation.PlayAttackAnim(); AttackSpeedWait = 0f; } AttackSpeedWait += Time.deltaTime; } }