Files
project-reset/Assets/Scripts/Units/Enemy.cs

69 lines
1.9 KiB
C#

using System;
using Reset.Core;
using Sirenix.OdinInspector;
using Unity.Netcode;
using UnityEngine;
namespace Reset.Units{
public class Enemy : Unit, ILockOnTarget, IKillable {
// Lock-On
public float lockonTargetRadius{ get; set; } = 10f;
[ShowInInspector]
public bool lockonDebug{ get; set; } = true;
public float lockonRaycastVerticalOffset{ get; set; } = 1f;
// IKillable
public float maxHealth{ get; set; }
public float currentHealth{ get; set; }
// Object References
public Animator testModelAnimator;
public override void UnitStart(){
base.UnitStart();
((IKillable)this).IKillableInitialize();
}
public void OnTargetDelete(){
GetComponent<ILockOnTarget>().SafelyDeleteTarget();
}
public void TakeDamage(DamageSource[] sources){
foreach (DamageSource source in sources) {
TakeDamage(source);
}
}
public void TakeDamage(DamageSource source){
if (UnitIsNetworked()) {
TakeOwnershipRpc((source.source as GameObject).GetComponent<NetworkObject>().OwnerClientId);
}
try {
currentHealth -= source.damageDealt;
if (UnitIsNetworked()){
SetHealthRpc(currentHealth);
}
testModelAnimator.SetTrigger("Hit");
if (currentHealth <= 0) {
Kill();
}
} catch (Exception e) {
Debug.LogError($"Failed TakeDamage on {this.name}: {e.Message}");
}
}
[Rpc(SendTo.Everyone)]
public void SetHealthRpc(float newHealth){
currentHealth = newHealth;
}
public void Kill(){
throw new System.NotImplementedException();
}
}
}