CapersProject/Assets/02.Scripts/BlueWater/Prop/SpineDamageableProps.cs

71 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections;
2025-02-10 02:13:46 +00:00
using DDD.Audios;
using DDD.Items;
using DDD.Utility;
using DDD.Players;
using UnityEngine;
2025-02-10 02:13:46 +00:00
namespace DDD
{
public class SpineDamageableProps : DamageableProps
{
[SerializeField]
private SpineController _spineController;
[SerializeField]
private string _idleAnimationName;
[SerializeField]
private string _touchAnimationName;
[SerializeField]
private string _dieAnimationName;
private Coroutine _touchCoroutineInstance;
private void Awake()
{
_spineController = GetComponent<SpineController>();
}
2025-02-24 11:55:35 +00:00
protected override void Start()
{
2025-02-24 11:55:35 +00:00
base.Start();
_spineController.PlayAnimation(_idleAnimationName, true);
}
private void OnTriggerEnter(Collider other)
{
2025-02-24 02:55:22 +00:00
if (!other.CompareTag("Player") || CurrentHealthPoint <= 0 || string.IsNullOrEmpty(_touchAnimationName)) return;
Utils.StartUniqueCoroutine(this, ref _touchCoroutineInstance, TouchCoroutine());
}
private IEnumerator TouchCoroutine()
{
var touchTrack = _spineController.PlayAnimation(_touchAnimationName, false);
while (!touchTrack.IsComplete)
{
if (CurrentHealthPoint == 0) yield break;
yield return null;
}
_spineController.PlayAnimation(_idleAnimationName, true);
}
public override void Die()
{
if (!string.IsNullOrEmpty(DieSfxName))
{
AudioManager.Instance.PlaySfx(DieSfxName);
}
_spineController.PlayAnimation(_dieAnimationName, false);
2024-08-22 10:39:15 +00:00
if (!string.IsNullOrEmpty(CharacterIdx))
{
2025-02-10 02:13:46 +00:00
//ItemManager.Instance.ItemDropRandomPosition(CharacterIdx, transform.position, 0f);
}
}
}
}