76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemyShip : MonoBehaviour
|
|
{
|
|
public ShipType Type;
|
|
|
|
[SerializeField] private BezierRunner Mover;
|
|
[SerializeField] private float MaxHp;
|
|
public Health HealthComponent;
|
|
[SerializeField] private List<Hitbox> Hitboxes;
|
|
[SerializeField] private EnemyHealthBar HealthBar;
|
|
|
|
[SerializeField] RealisticSinking sinking;
|
|
|
|
public Weapon weapon;
|
|
|
|
|
|
public int SpawnCost = 100;
|
|
public int Score = 100;
|
|
|
|
public static event Action<EnemyShip> ShipSpawned; //Побежден
|
|
public static event Action<EnemyShip> ShipDefeated; //Побежден
|
|
public static event Action<EnemyShip> ShipReleased; //Отпущен
|
|
|
|
public void Initialize()
|
|
{
|
|
foreach (var hitbox in Hitboxes) { hitbox.Initialize(gameObject); }
|
|
HealthComponent.Initialize(MaxHp, Hitboxes);
|
|
HealthComponent.Died += Defeat;
|
|
|
|
ShipSpawned?.Invoke(this);
|
|
Mover.OnReachedEnd += Release;
|
|
|
|
HealthBar?.Initialize(HealthComponent);
|
|
}
|
|
public void AssignToWay(BezierWay way)
|
|
{
|
|
way.SetBusiness(true);
|
|
Mover.SetBezierWay(way);
|
|
}
|
|
|
|
public void Defeat(Vector3 damagePosition)
|
|
{
|
|
ShipDefeated?.Invoke(this);
|
|
Mover.BezierWay.SetBusiness(false);
|
|
Mover.OnReachedEnd -= Release;
|
|
|
|
sinking.OnTorpedoHit(damagePosition, Mover.Velocity);
|
|
Mover.enabled = false;
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
ShipReleased?.Invoke(this);
|
|
Mover.BezierWay.SetBusiness(false);
|
|
Mover.OnReachedEnd -= Release;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Release();
|
|
}
|
|
|
|
|
|
public enum ShipType
|
|
{
|
|
CombatBoat,
|
|
Frigate,
|
|
Destroyer,
|
|
Destroyer2,
|
|
Carrier
|
|
}
|
|
}
|