using System.Collections; using System.Collections.Generic; using UnityEngine; public class Archer : Ally { [SerializeField] private GameObject _arrow; private Rigidbody2D _rigidbodyAlly; private Rigidbody2D _rigidbodyOpponent; public override void Start() { base.Start(); _rigidbodyAlly = GetComponent(); Animation = gameObject.AddComponent(); } void Update() { if(IsEnemyDetected) { _rigidbodyOpponent = Enemy.GetComponent(); AttackEnemy(); } } void AttackEnemy() { //Attack Cooldown if(AttackSpeed < AttackSpeedWait) { Animation.PlayAttackAnim(); GameObject _newArrow = Instantiate(_arrow, _rigidbodyAlly.position, Quaternion.identity); //Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable ! _newArrow.GetComponent().Damage = AttackDamage; _newArrow.GetComponent().EnemySpeed = Enemy.Speed; _newArrow.GetComponent().VectorStart = _rigidbodyAlly.position; _newArrow.GetComponent().VectorEnd = _rigidbodyOpponent.position; _newArrow.GetComponent().Target = Enemy; AttackSpeedWait = 0f; } AttackSpeedWait += Time.deltaTime; } }