Particle Collision Sound Effects

I’m trying to create a script that I can attach to any prefab to make a specific sound every time a particle collides with it. This script is currently attached to the “ground” prefab. The script runs without error, but the sound(s) do not play. And yes, the prefab has an Audio Source component (default settings).

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]

public class particleSound : MonoBehaviour {

    public AudioClip soundEffect;
    AudioSource audio;

    void Start() {
        audio = GetComponent<AudioSource>();
    }

    void OnParticleCollision ()
    {
        audio.PlayOneShot(soundEffect, 1.0F);
    }
}

did you enable sendCollisionMessage in the inspector?

1 Like