- Home /
Question by
KojiArala · Jul 14, 2016 at 04:37 AM ·
scripting problemaudiosource
How Can I Toggle External Audio Sources?
Hey there all. I've been trying to figure this out from other questions, but it's not clicking for me. I'm trying to script an object that will turn off all other audio sources, play its sound, then turn then back on. Right now, I'm just trying to get the idea of "outside audio sources shut off from trigger in this object" sorted. Here's what I've got. I'm not getting any errors, but hitting space isn't silencing the audio sources.
void Update () {
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
if(Input.GetKeyDown (KeyCode.Space))
Debug.Log("space key was pressed");
GameObject toneCube = GameObject.Find("toneCube");
if(toneCube != null)
{
AudioSource cubeSound = toneCube.GetComponent<AudioSource>();
if(cubeSound != null)
{
cubeSound.mute = true;
}
}
}
}
Comment