So,
I’ve made a script called DestroyBySword that i’d like to be able to drop on any object that will be able to be destroyed by a sword.
I’d like the following to happen when the sword Collider(Tagged “Sword”) enters the collider on the object.
1.Play a sound
2.Play a burst particle system for whatever the debris looks like for that object
and finally
3.Destroy the object.
In this scenario I’ve made a clump of grass object with the DestroyBySword script attached
I’ve also attached a audio source to the object
I’ve also parented a particle system that bursts some grass looking particles.
My script allows for dropping in an audio source and a particle system.
I did this for the flexibility of using this one script for all destructible objects in my game.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyBySword : MonoBehaviour
{
public AudioSource ImpactSound;
public ParticleSystem Debris;
void Start()
{
ImpactSound = GetComponent();
Debris = GetComponent();
}
void Update()
{
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == “Sword”)
Debris.Play();
ImpactSound.Play();
Destroy(this.gameObject);
}
}
The object destroys but neither the audio nor the particle system plays.
What am I doing wrong here?