- Home /
Figuring out multiple audio in scene
Hello,
I have three game objects. When the player collides with one, a video starts to play. However and normally editor says sth like "multiple audio source, you should need one". And video plays silent-no sound. How can I make it flowing smoothly? I need all video and sounds.
Platform is PC btw.
If you provide your code and details on how your objects are setup in the editor, we would be better able to assist you.
However, in general, if you want an audio clip to play when your player object collides with an obstacle you can put code on the obstacles that checks during collision if it has collided with the player object by using tags, and then if the tag is "player" (or whatever you set it to), then play the audio clip.
void OnTriggerEnter(Collider temas)
{
if (temas.gameObject.name.StartsWith("Player"))
{
flag = true;
}
}
// Use this for initialization
void Start ()
{
timer = 0;
}
// Update is called once per frame
void Update ()
{
if (flag)
{
timer += Time.deltaTime;
}
}
void OnGUI()
{
if (flag)
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), cine_ask);
cine_ask.Play();
if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Escape) || cine_ask.duration < timer)
{
cine_ask.Stop();
Destroy(gameObject);
flag = false;
GameObject.FindGameObjectWithTag("guiOne").guiTexture.enabled = true;
}
}
}
}
As I said before there are three objects. And they have three different videos. So if I reduce these listeners to one, how can I assign video's audio?
@agostevethorne, you are incorrect. You can have as many audio sources
in your scene as you want. It is the audio listener
that you should have only one of, and it is by default already attached to the main camera.
Answer by guitarxe · Dec 13, 2013 at 03:44 PM
I don't see any code here that even tries to play an audio clip.
Read up here
http://docs.unity3d.com/Documentation/Components/class-AudioClip.html http://docs.unity3d.com/Documentation/Components/comp-AudioGroup.html
And watch this video tutorial
http://unity3d.com/learn/tutorials/modules/beginner/audio/lessons/audio-sources-and-listeners
After having done so, try to first do it on your own, then if you are still having problems come back and describe what specific problem you are having.
the video plays the audio. did you read the question or what?
Your question is not very clear, then. Why are you trying to play a different audio from what is already with the video?
@guitarxe is right here and in his comment above.
The audio listener is like your player's ears. It tells Unity where sound volume and effects should be measured from for output to the speakers. You could certainly make an argument that Unity should allow multiple listeners - for instance, for a spy game where you want to be able to bug another room. But at least for now, that's the limitation.
Also, you should go and fix your question - you mention audio sources when you really mean audio listeners, and like @guitarxe I don't see any reference to audio in the code snippet you provided. You have code for playing cine_ask, but it's impossible to tell from what you've posted whether cine_ask is a $$anonymous$$ovieTexture or an AudioSource. $$anonymous$$eep in $$anonymous$$d that when you play a video it doesn't automatically play the audio track for the video - you have to extract it and play it separately.
Not a big deal - we just need good information if we're going to give you good answers.
I am really shocked when I have seen your comments. It is very clear that I stated my problem is video related. Since my video have also audio, the editor did not like the situation. Because system needs audio listener for each audio source. Hence there are same number of listeners with number of video. At that point please ignore your wisdom and expertise.
Long story short; How can I assign each video's audio piece programmatically/on runtime? Thanks in advance.
I think you may be misunderstanding a few things about Unity. That's okay! We'll try to help you understand.
Because system needs audio listener for each audio source.
This is incorrect, and Unity will throw errors if you try this. There is only one audio listener regardless of the number of audio sources.
Since my video have also audio, the editor did not like the situation.
The problem is not that the editor does not like video that also has audio. The problem is somewhere else, and we're trying to figure out where. Are you extracting the audio for your video by using http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$ovieTexture-audioClip.html ? Are you then assigning the AudioClip to an AudioSource? Are you then calling Play() on the AudioSource?
Your answer
![](https://koobas.hobune.stream/wayback/20220613124059im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Passing Audio to an Android service? 0 Answers
3d Sound not working? 1 Answer
How to Switch The Audio Clip using button 0 Answers
Make Sound Effects Not Audible Unless Near Them 2d? 1 Answer
Mute 1 audio channel while preserving spatialized 3D sound? 0 Answers