50 lines
923 B
C#
50 lines
923 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Opponent : Entity
|
|
{
|
|
|
|
private Vector2 _movementVector = Vector2.zero;
|
|
private Rigidbody2D _rigidbody;
|
|
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_rigidbody = GetComponent<Rigidbody2D>();
|
|
Animation = gameObject.AddComponent<AnimationEntity>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if(IsEnemyDetected) {
|
|
AttackEnemy();
|
|
}else {
|
|
_movementVector.x = -Time.deltaTime * Speed;
|
|
|
|
transform.position += (Vector3)_movementVector;
|
|
|
|
Move();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
void AttackEnemy()
|
|
{
|
|
//Attack Cooldown
|
|
if(AttackSpeed < AttackSpeedWait)
|
|
{
|
|
Animation.PlayAttackAnim();
|
|
|
|
AttackSpeedWait = 0f;
|
|
}
|
|
|
|
AttackSpeedWait += Time.deltaTime;
|
|
}
|
|
|
|
}
|