I am using a circular trigger to act as a damage collider (when player hits enemy trigger, player gets hurt). My problem is, whenever I enter the trigger it plays, and then when I exit it plays multiple times until I die. I assume this is caused by me entering and exiting the trigger rapidly (since it’s a circle) but I can’t find a fix. Here’s the code
#pragma strict
private var SanityEffect : InsanityGUI;
var scarePercent : float = 20.0;
var ScareSound : AudioClip;
function Start()
{
SanityEffect = GameObject.Find("FPSController").GetComponent(InsanityGUI);
}
function OnTriggerEnter (Col : Collider)
{
if(Col.tag == "Player")
{
SanityEffect.currentSanity += scarePercent;
GetComponent.<AudioSource>().PlayOneShot(ScareSound);
}
}