OnControllerColliderHit keeps looping...
Hey guys. So, I am making it so that, when the player (which has a Character Controller on it) hits FL1 (the floor), it calls the routine and these 3 parameters go to 20, then, it waits a second, and puts them back to 0. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ChangeGlitch : MonoBehaviour
{
public AudioSource glitch;
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.collider.name == "FL1")
{
StartCoroutine(Glitch());
}
IEnumerator Glitch()
{
glitch.Play();
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().flipIntensity = 20;
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().intensity = 20;
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().colorIntensity = 20;
yield return new WaitForSeconds(1);
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().flipIntensity = 0;
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().intensity = 0;
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GlitchEffect>().colorIntensity = 0;
Destroy(GameObject.Find("FL1"));
}
if (hit.collider.gameObject.layer == 9)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>().isGrounded = true;
}
}
}
The problem is that I think the whole thing keeps looping. When I touch the floor (FL1), the sound is repeating after (not even a millisecond) of it being played. I just want to make it somehow execute the routine ONCE, and then stop.
Comment