- Home /
Musical game mute and unmute trigger soundsource
(extreme noob question im sure)
i am creating a game in which i can create the elements of a song (different tracks) by shooting through trigger cubes. at the moment all i can get is a mess off sounds that dont sync.
i was wondering if there is a way to play all the sounds at the same time but have them on mute, then to be able to unmute and mute a cubes sound source everytime it is triggered by a rigidbody. that way they would all be in time if i kept it at a steady tempo and time signeture.
any ideas?
Answer by AlucardJay · Mar 29, 2012 at 11:55 PM
This is tested and working. I have 2 Cubes on stage , both with an Audio Source, Audio Clip loaded in the Inspector, Play-on-awake is toggled OFF .
The main script (hopefully) shall start all the cubes playing together (in sync).
#pragma strict
var cube1 : Transform;
var cube2 : Transform;
private var cubeSelected : Transform;
function Awake () {
cube1.audio.Play();
cube2.audio.Play();
cube1.audio.mute = false;
cube2.audio.mute = false;
}
function Update () {
if (Input.GetKeyDown(KeyCode.Mouse0))
{
var rayHit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), rayHit))
{
cubeSelected = rayHit.transform;
// mute / unmute selected cube
if (cubeSelected.audio.mute) {
cubeSelected.audio.mute = false;
} else {
cubeSelected.audio.mute = true;
}
}
}
}
This would be good for an on-the-fly mixer. If you wanted to have only one cube playing , you would have to code that in so all are mute except the selected.
[1]: http://answers.unity3d.com/questions/231526/trigger-sound-when-walking-through-cube-trigger.html
Hello, did this script work, or did you find the suggestion useful? Please post a comment or mark an answer, for future reference by other people searching this 'site.
i think this is what im after, but im not sure what im supposed to attach the script to?
you can just attach this script to the $$anonymous$$ain Camera =]
Or create an empty gameObject and attach it to that. Or you can place it into your current player script. All it does is raycast to a cube from the mouse pointer , and toggles that cube's mute functionality on the Audio Source component.
How did you go ?
Your answer
Follow this Question
Related Questions
How do I mute one sound source using another? 1 Answer
Function that does not affect him Time.timeScale? 1 Answer
Audio Playing upon death 1 Answer
Lost sound on iphone after alarm clock goes off 0 Answers
Mute volume / sound problem 1 Answer