2023-07-07 19:15:56 -04:00

58 lines
1.5 KiB
C#

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<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>();
}
void Update()
{
if(IsEnemyDetected) {
_rigidbodyOpponent = Enemy.GetComponent<Rigidbody2D>();
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<Projectile>().Damage = AttackDamage;
_newArrow.GetComponent<Projectile>().EnemySpeed = Enemy.Speed;
_newArrow.GetComponent<Projectile>().VectorStart = _rigidbodyAlly.position;
_newArrow.GetComponent<Projectile>().VectorEnd = _rigidbodyOpponent.position;
_newArrow.GetComponent<Projectile>().Target = Enemy;
AttackSpeedWait = 0f;
}
AttackSpeedWait += Time.deltaTime;
}
}