Forum rules - please read before posting.

Play sound on many objects

edited June 2015 in Technical Q&A
How do I play sound when I click on many other objects and the sound does not reset? Just with one sound object.

I have many onMouseDown objects and they all use the same sound object ( with sound script attached) ,all objects have separate actionlists and in each I have Sound: Play of my sound object. Every time I quickly click on objects sound effect is reset.

How do I make it all play on without resets and just with one sound object.
I really dont want to make 20 the same sound object and assign them in each actionlist.

Cheers

Comments

  • edited June 2015
    I don't totally follow you here, are you talking about a Menu element's "Click sound"?

    If so, try opening up SceneSettings.cs and edit line 158:
    if (audioClip && defaultSound.GetComponent <AudioSource>())

    to read:
    if (audioClip && defaultSound.GetComponent <AudioSource>() && !defaultSound.IsPlaying ())
  • edited June 2015
    Not menus or UI, just game objects.
    I just have hotspots, each has this action below, I click on them and play the same sound object.

    image


    And this is my sound object
    image

    Every time I click on hotspots the sound is reset and plays from the start.
    How do I make it play on with out resets?
    I know I can create 20 more sound objects and assign them. Like 1 sound object for hotspot 1, 2 sound object for hotspot 2 and so on, in that way the sounds will play on with out resets. But I would rather not do it that way.

    So I'm wondering how can this be avoided.
  • By "play on without resets", do you mean that if the sound is already running, don't restart it?  That's what the "Ignore if already playing" checkbox is for.  If not, please explain what you mean exactly.
  • edited June 2015
    Click object 1, sound starts to play.
    Click object 2, sound stops and starts to play from the start. Not good.

    I want:
    Click object 1, sound starts to play. And continues so.
    Click object 2, sound starts to play. And continues so.
    Click object 3, sound starts to play. And continues so.
    and so on...

    I don't want "Ignore if already playing" . I want the new sounds and the old sounds keep playing.
  • Unfortunately, that's just inherent to how Unity works: an AudioSource component can only play one sound clip at a time.  It may be possible to create a workaround in a future release (or sooner by writing a custom action), but right now the only way would be to create a separate sound object for each clip.
  • edited June 2015
    Weird. So how one would go about spamming objects and play sounds.
    Say you fire at random gazillions rockets from a launcher.

    You would probably need to create a script that creates a sound object and attach it to every single rocket that is spawned?

  • That'd be the Unity way, yes.
  • Update: Seems Unity added some nice features to get around this.  Look out for a new Action to handle this in the next release.
  • edited March 2020

    Hello @ChrisIceBox I just stumbled onto this thread and I'm looking for the same solution. Could you point me in the right direction on how to get this to work?

    I have 4 hotspots that each use the action "Play Sound"
    I want to be able click on them separately and have the sounds play together

    If I use the action "Play Oneshot", I can get them to play together, but then I can spam the hotspot and replay that same sound which is not what I'd like.

    :)

  • Welcome to the community, @BuckWillis.

    I'm afraid I'm not clear on your meaning - does each Hotspot make its own sound? If the sounds are separate, you'd typically want each Hotspot to trigger its own Sound object.

    If you can explain the situation from a gameplay/puzzle design perspective, that'll help me to figure out the best way forward.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.