Files
2026-05-26 16:15:54 +08:00

49 lines
1.3 KiB
C#

using System;
using UnityEngine;
public class ShootingTarget : MonoBehaviour
{
public int stageIdx, targetIdx;
public Animation ani;
private const string Break = "breaking", Broken = "broken", Normal = "normal", Appear = "into";
public void InitAndPlayAppearAnimation(bool isHit, int stageIdx, int targetIdx)
{
this.stageIdx = stageIdx;
this.targetIdx = targetIdx;
gameObject.SetActive(!isHit);
if (!isHit)
PlayAppear();
}
public async System.Threading.Tasks.Task PlayBreakAnimationWithDelay(float delay = 0f)
{
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(delay));
ani.Play(Break);
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(14f / 60));
gameObject.SetActive(false);
}
public void PlayAppear()
{
try{
ani.Play(Appear);
}
catch(Exception e)
{
Debug.LogError(e.Message);
Debug.LogError(e.StackTrace);
}
}
// private void Start()
// {
// var enumerator = ani.GetEnumerator();
// using var d = enumerator as IDisposable;
// while (enumerator.MoveNext())
// {
// Debug.Log(enumerator.Current);
// }
// }
}