Ader Alisma 01 6345febb35 Start reworking constant spawn
Made interval between spawns adapt to enemies spawned at the Start

Removed the random factor of interval to respect the game duration

Made max spawn per row dependent of enemy toughness on that row
2023-09-10 15:39:19 -04:00

61 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Opponent : Entity
{
private Vector2 _movementVector = Vector2.zero;
private Rigidbody2D _rigidbody;
private WaveObserver _observer;
private int _observerIndex;
private float _toughness;
public override void Start()
{
base.Start();
_rigidbody = GetComponent<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>();
_observer = WaveObserver.Instance;
_toughness = Mathf.Round((base.Hp / 10) / 2);
_observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness);
}
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;
}
private void OnDisable()
{
_observer.NotifyDies(_observerIndex, _toughness);
}
}