Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ontriggerenter question - controlling proper audio

Discussion in 'Scripting' started by jalapen0, Oct 19, 2014.

  1. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136
    Hello,

    Lets say I have 2 cubes, both with rigidbodies, and 2 colliders. One collider on each cube is a trigger. All physics and ontriggerenter functions work great.

    Now to the problem and question, I have a collision sound that plays oncollisionenter on each cube. This is so that if I have another object that strikes them, it will play the collision sound and everyone is happy. All this works perfectly. The problem though, what if the cubes strike each other? 2 sounds get played. I only want one sound to play. How to supress one sound so only one plays?

    Thanks!

    edit: of course, it's ontriggerenter, not oncollisionenter. Made the changes.
     
    Last edited: Oct 20, 2014
  2. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136
    Incredibly shameful and pathetic bump.
     
  3. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    this is definitely an awkward situation.
    could you tell us how did you play the audio clip
     
  4. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    quick and dirty way is.
    use AudioSource.PlayAtPoint() for playing clips
    you can start with adding tag to the cubes. then separate the things you do when collision is detected.

    if(other.tag == "cube"){
    if(// there is no gameobject named "AudioSource")
    // play the sound
    }