I put an audio in my “Main Camera”, then created a button to stop this “audio”
How can I make a script to stop this “audio” that is “Main Camera”, when you touch that button?
I tried to do so, but it did not work
void Update () {
if(Input.touchCount == 1)
{
var ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
if(hit.transform.tag == "musica"){
GameObject noMusicIns;
audio.Stop();
noMusicIns = (GameObject)Instantiate(noMusic, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}
}
Can anyone help me?