Sound on trigger script only plays once.
Hey guys,
I have this sound on trigger script, that only trigger the sound once, and then I have to reset the game to "re-trigger" the sound. What do I have to change to get the sound trigger to "reset", when I exit the trigger zone, so I can trigger the sound infinite times?
public class play_sound_on_trigger : MonoBehaviour
{
public bool activateTrigger = false;
public GameObject textO;
public GameObject Sound;
void Start()
{
textO.SetActive(false);
Sound.SetActive(false);
}
void Update()
{
if (activateTrigger && Input.GetKey(KeyCode.E))
{
textO.SetActive(false);
Sound.SetActive(true);
}
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
textO.SetActive(true);
activateTrigger = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Player")
{
textO.SetActive(false);
activateTrigger = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
2D Power up script not working 0 Answers
2D Power up script not working 0 Answers
audio trigger not working 0 Answers
Play sound when looking at an object for a certain amount of time 0 Answers
Audio Trigger 2D in C#? 1 Answer