I’m developing a 2D game, and have a Button prefab what plays a sound when clicked.
I have multiple instance of this prefab on my scene, but only 2 of them plays the sound, the others don’t play anything, or just a very short something.
I thought that it is caused by the distance of the camera and the gameObject, but if I place a button what is silent, to the position of a working button, it still won’t play anything.
My code is simple:
...
public AudioSource myAudioSrc;
public AudioClip btnSound;
...
protected virtual void OnMouseUpAsButton() {
if(!isEnabled) { return; }
myRenderer.sprite = normalImg;
transform.localScale = normalSize;
myAudioSrc.PlayOneShot(btnSound);
Debug.Log(gameObject.name);
//üzenet küldése az objektumnak a message metódus hívására az data paraméterrel
target.SendMessage(message, data);
}
...
EDIT:
I’ve got this working with the code:
AudioSource.PlayClipAtPoint(btnSnd, Camera.main.transform.position);
So it has to do something with the distances.
Is there any better solution?