I have gameobject A that got script that wants to play audiosource 1 and 2. Sources are located on different gameobject. I can make it play the same audiosource on that gameobject. But not the second one. How can i solve this?
1 Answer
1A snip of the code would help to see the problem but this is how I handled sound
Here is an example of my code where it plays 2 sound when an item is picked up
public AudioClip CoinCol;
public AudioClip ScoreSound;
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
audio.Stop(); // Stop Sound
MultiScore multiScore = WorldSettings.GetComponent <MultiScore> ();
other.gameObject.SetActive(false);
multiScore.Pcount = multiScore.Pcount + 1;
Debug.Log(multiScore.Pcount);
SetCountText();
audio.PlayOneShot(CoinCol, 1F); // Play Coin Collect sound
audio.PlayOneShot(ScoreSound, 1F); // Play Score Sound
}
}
Use Audioclip as the variable
you can use audio.Stop(); to stop sound
multiple sounds can be played on one AudioSource using .PlayOneShot but if you want to play the
sound at a position in the world use .PlayClipAtPoint