Quantcast
Channel: Questions in topic: "endless"
Viewing all articles
Browse latest Browse all 123

PlayOneShot keeps playing for ever (loops)

$
0
0

for easily(er) playing some soundeffects, I made a small script:

SoundController:

private static var Singleton : GameObject;  

static function GetController()
{   
    if (!Singleton) Create();
    return Singleton;
}

private static function Create()
{
    Singleton = new GameObject("SoundObject");
    Singleton.AddComponent(SoundScript);
    Singleton.AddComponent(AudioSource);
}

static function Play(sound:AudioClip,volume: float)// = 1.0F) : void
{   
    if (!Singleton) Create();
    Singleton.audio.PlayOneShot(sound,volume);;
}

So I can just do

SoundController.Play(sound,1);

Only problem is it keeps playing the sound over and over as soon as it first starts.

Why did I do wrong ?

EDIT:

answer: Nothing. I don't think I actually did anything wrong, cause it works now. Could it be a caching problem of some sort in Unity? (no idea how that would have this effect but I just don't know what else it could be)


Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>