2
votes

my environment:
Win7 x64
Unity Pro 3.5.5
c#(Visual studio 2010)

my objective:
i am making a mobilegame with unity3d.
and i making a bombeffect.
the effect plays its own sound when it is showing.

spec:
the effect is maked a single prefab with a plan, sprite texture.
and has a Audiosource (drag&dropped a wav file to Prefab in Inspector)
the bombeffect is managed by my custom object pool so i disabled play on awake option in Inspector. (because it recycled by my custom rule)
so i coded that :

//when the booming is begin

GameObject obj;
obj = MyObjectPool.Recycle("Prefabs/BombEffect");  //try recycle
if(obj != null)
{
    //every object's first creation is doing here
    obj = Instantiate("Prefabs/BombEffect") as GameObject;
    MyObjectPool.StartManage(obj);
}
obj.audio.play(); //play

problem:
the bombeffect is rapidly created. (the attack speed is very fast)
but the sound playing is works like a SINGLETON. it means if the bombeffect audio is start playing, than other bombeffect gameobject's audio can't played. until the first PLAYING bombeffect is stop naturally.

but according to my knowledge, a prefab's Audio Source is can multiple-played sametime with another prefab's Audio Source. but it is not. i don't understand. how can i play multiple-play same audio wav file ?

1

1 Answers

0
votes

I think you may have a problem with your logic. If MyObjectPool does not have any objects availiable in it MyObjectPool.Recycle() will return null, unless your Recycle() implementation is doing something I am not aware of.

I think this is what you are looking for:

    if(obj == null)
    {
       //every object's first creation is doing here
       obj = Instantiate("Prefabs/BombEffect") as GameObject;
       MyObjectPool.StartManage(obj);
    }

What is probably happening is that you are never actually instantiating more that one object. Once it finishes playing it returns to the pool and is then recycled to be played again.