28 lines
557 B
C#
28 lines
557 B
C#
using UnityEngine;
|
|
|
|
public class DestroyAfterAnimation : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Animator animator;
|
|
|
|
private void Awake()
|
|
{
|
|
if (animator == null)
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (animator == null)
|
|
return;
|
|
|
|
AnimatorStateInfo state =
|
|
animator.GetCurrentAnimatorStateInfo(0);
|
|
|
|
if (state.normalizedTime >= 1f
|
|
&& !animator.IsInTransition(0))
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |