When I start the game and trigger the animation, it plays only the first frame and ends soon. When I look at it in the Animator window during the game, I see only 15% of that animation playing and stopping shortly after.
I already have unchecked “Can Transition To Self” and “Has Exit Time”.
Thanks in advance.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerLife : MonoBehaviour
{
private Rigidbody2D rb;
private Animator anim;
// Start is called before the first frame update
private void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Trap"))
{
Lose();
}
}
private void Lose()
{
rb.bodyType = RigidbodyType2D.Static;
anim.SetTrigger("lose");
}
private void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}