I am trying to play a sound which is attached to a mixer when something is hit by a ball. The code works without the coroutine and no destroy gameobject in the code, but the brick needs to delete when hit and i think my code is the best way to do it (although i am probably wrong). But the problem is that i can’t get the coroutine to start on a collision with an object. I removed the collision part of the code i was trying in order to allow the code to work but now all the objects this is attached too delete after 1 second.
How can i start a coroutine on a collision or if that is not possible what is a work around.
Thanks for any and all help.
using UnityEngine;
using System.Collections;
public class Bricks : MonoBehaviour
{
public GameObject brickParticle;
public AudioClip Brick_breaking;
private AudioSource SoundFx;
void Awake()
{
SoundFx = GetComponent<AudioSource>();
StartCoroutine(Example());
}
IEnumerator Example()
{
SoundFx.PlayOneShot(Brick_breaking, 1F);
Instantiate(brickParticle, transform.position, Quaternion.identity);
GM.instance.DestroyBrick();
yield return new WaitForSeconds[1];
}
}