- Home /
This question was
closed Jul 18, 2018 at 08:25 AM by
Snoxorus for the following reason:
Other
Question by
Snoxorus · Jul 18, 2018 at 12:30 AM ·
audiosoundaudio source
Why does my audio stop working?
I have setup a script to play a sound from the audio source attached to the gameobject when it is collided with and works perfectly everytime.
Problem When I save and close unity then reopen the project, the sound no longer works when triggered. The same happens when switching scenes.
There are no errors in my code.
public Material noiseTexture;
public Material scareTexture;
public AudioSource scareSound;
public Renderer rend;
public float scareTime = 3f;
void Start()
{
scareSound = GameObject.FindObjectOfType<AudioSource>();
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
StartCoroutine("Scare");
}
}
public IEnumerator Scare()
{
scareSound.enabled = true;
scareSound.Play();
Debug.Log("played sound");
rend.material = scareTexture;
yield return new WaitForSeconds(scareTime);
scareSound.Stop();
rend.material = noiseTexture;
}
}
Comment
Best Answer
Answer by Snoxorus · Jul 18, 2018 at 08:24 AM
Nevermind, I have figured it out myself since no one helped.