Baptiste 6c23b4b99c v0
2023-06-13 09:47:55 -04:00

53 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;
void 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.Attack();
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;
}
}