Hey guys im trying to create a crate that my character can destroy and then a animation starts playing from the crate getting destroyed but for some reason my crate gets destroyed before the animation can start playing please help me fix this issue:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Crates : MonoBehaviour
{
public Rigidbody2D rb;
private Animator anim;
public bool crate;
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
anim.SetBool("crate", false);
crate = false;
}
void Update()
{
if (crate)
{
anim.SetBool("crate", crate);
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Player")
{
crate = true;
Destroy(transform.parent.gameObject);
}
}
}