So heres my projectile script, I used Brackey’s tutorial for it since I am pretty new to unity, and I have an impact animation set up so after it impacts it should do the animation and desrtoy it self. The final frame of the impact effect stays in game and the projectile doesn’t destroy it self even though I tell it to in the script. Not sure if my problem is with the projectile not destroying itself or if its my animation, thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProjectileBehaviour : MonoBehaviour
{
public float Speed = 20f;
public int damage = 20;
public Rigidbody2D rb;
public GameObject impactEffect;
void Start()
{
rb.velocity = transform.right * Speed;
}
void OnCollisionEnter2D(Collision2D hitInfo)
{
Enemy enemy = hitInfo.transform.GetComponent<Enemy>();
if (enemy != null)
{
enemy.TakeDamage(damage);
}
Instantiate(impactEffect, transform.position, transform.rotation);
Destroy(gameObject);
}
}