OldBlueWater/BlueWater/Assets/02.Scripts/HouseInfo.cs

74 lines
1.7 KiB
C#
Raw Normal View History

2023-09-04 07:31:04 +00:00
using Sirenix.OdinInspector;
using UnityEngine;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
[SelectionBase]
public class HouseInfo : MonoBehaviour, IDamageable
{
#region Property and variable
2023-09-04 07:31:04 +00:00
[SerializeField] private IslandInfo islandInfo;
[SerializeField] private float maxHp = 500f;
2023-09-04 07:31:04 +00:00
[DisableIf("@true")]
[SerializeField] private float currentHp;
#endregion
#region Unity built-in function
private void Awake()
{
2023-09-04 07:31:04 +00:00
SetCurrentHp(maxHp);
}
private void OnDisable()
{
RemoveIslandInfo();
}
#endregion
#region Interface property and function
public void TakeDamage(float attackerPower, Vector3? attackPos = null)
{
2023-09-04 07:31:04 +00:00
var changeHp = Mathf.Max(currentHp - attackerPower, 0);
SetCurrentHp(changeHp);
// 건물 파괴
if (changeHp == 0f)
{
Die();
return;
}
}
public void Die()
{
Destroy(gameObject);
RemoveIslandInfo();
}
#endregion
#region Custom function
private void RemoveIslandInfo()
{
2023-09-11 07:16:02 +00:00
if (islandInfo == null) return;
2023-09-04 07:31:04 +00:00
islandInfo.RemoveListElement(islandInfo.HouseList, transform);
islandInfo.RemoveListElement(islandInfo.TargetAllList, transform);
}
2023-09-04 07:31:04 +00:00
public float GetCurrentHp() => currentHp;
public void SetCurrentHp(float value) => currentHp = value;
public void SetIslandInfo(IslandInfo island) => islandInfo = island;
#endregion
}
}