2023-06-25 18:14:45 -04:00

50 lines
1020 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Opponent : Entity
{
private Vector2 _movementVector = Vector2.zero;
private Rigidbody2D _rigidbody;
void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>();
}
void Update() {
_movementVector.x = -Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
if(IsEnemyDetected) {
AttackEnemy();
}
}
void AttackEnemy() {
//Attack Cooldown
if(AttackSpeed < AttackSpeedWait)
{
Animation.Attack();
Enemy.hit(AttackDamage);
Debug.Log("Ally Hp = " + Enemy.Hp);
//Kill if no hp
if(Enemy.Hp <= 0) {
Enemy.death();
}
AttackSpeedWait = 0f;
}
AttackSpeedWait += Time.deltaTime;
}
}