71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Drawing;
|
|
using Reset;
|
|
using Reset.Core;
|
|
using Reset.Core.Tools;
|
|
using Reset.Units;
|
|
using UnityEngine;
|
|
using Sirenix.OdinInspector;
|
|
using Sirenix.Serialization;
|
|
using Unity.Netcode;
|
|
|
|
namespace Reset.Units{
|
|
public class Player : Unit, IKillable{
|
|
[HideInInspector] public PlayerControls controls;
|
|
|
|
float IKillable.maxHealth{ get; set; }
|
|
float IKillable.currentHealth{ get; set; }
|
|
|
|
void Awake(){
|
|
controls = GetComponent<PlayerControls>();
|
|
}
|
|
|
|
public void Attach(){
|
|
if (IsLocalPlayer || !UnitIsNetworked()) { //
|
|
PlayerManager.Player = gameObject;
|
|
|
|
PlayerManager.RequestNewController();
|
|
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
|
}
|
|
}
|
|
|
|
public override void UnitStart(){
|
|
base.UnitStart();
|
|
|
|
SetPlayerName();
|
|
Attach();
|
|
((IKillable)this).IKillableInitialize();
|
|
}
|
|
|
|
private void SetPlayerName(){
|
|
name = "Player";
|
|
if (UnitIsNetworked()){
|
|
name += IsLocalPlayer ? ", Local" : ", Network";
|
|
}
|
|
}
|
|
|
|
public override void UnitUpdate(){
|
|
GetComponent<IKillable>().DrawHealthDebug();
|
|
}
|
|
|
|
public void TakeDamage(DamageSource[] sources){
|
|
foreach (DamageSource source in sources) {
|
|
TakeDamage(source);
|
|
}
|
|
}
|
|
|
|
public void TakeDamage(DamageSource source){
|
|
((IKillable)this).currentHealth -= source.damageDealt;
|
|
|
|
if (((IKillable)this).currentHealth <= 0) {
|
|
Kill();
|
|
}
|
|
}
|
|
|
|
public void Kill(){
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
}
|
|
} |