Trying to get trigger zone to only trigger once

Hi there chaps,

I am trying to make my trigger area only trigger once. See my script below. The trigger does a couple of things, changing colour and affecting the speed of the object (‘Bingo’). It’s still triggering every time Bingo enters the trigger zone.

var target : Collider;
     private var triggered : boolean = false; 
     
    function OnTriggerEnter (Bingo : Collider) {
            Bingo.rigidbody.AddForce (0, 500, 0);
    		renderer.material.color = Color.green;
        }
    	
    	function OnTriggerExit (Bingo : Collider) {
           		renderer.material.color = Color.red;
        }
    	
    	triggered = true;

Not sure where I am going wrong there. Ideally I’d like to be able to trigger it once then reset it after say, 10 seconds.

Any help appreciated.

You got some things wrong. Here is what you could do (This is a c# equivalent)

//You dont need Collider col. if you are not going to use it
void OnTriggerEnter(Collider col)
{
   if(!entered)
   {
      //Code to be executed
      entered = true;
      inside = true;
   }
}

void OnTriggerExit(Collider col)
{
   if(inside)
   {
       //Code to be executed
       inside = false;
   }
}

Then you will want to have (in update maybe) something that counts the timer until entered resets to false.

Extra info:
The Collider col in the functions head is a reference to the object that is entering the Trigger. So if you dont use it in any way. It will be every gameobject that enters the area. So if maybe you have a NPC characther and a player character and you want the trigger to react different and execute different actions depending on if the Player enters the area or the NPC.

void OnTriggerEnter(Collider col)
{
    if (col.tag == "Player")
    {
    //Code to be executed
    }
    else if(col.tag == "NPC")
    {
    //Different code to be executed
    }
}

So lets say i have tagged the player with the tag “Player” and the NPC with the tag “NPC”
then depending on which object enters the area. The trigger will behave differently

You should use a bool variable to see if it’s triggered in last X seconds or not or use time as mesurement of the last time you entered the trigger.
var lastEnteranceTime=-100f;

function OnTriggerEnter(bingo : Collider)
{
if(Time.time - lastEnteranceTime > 10)
{
//Do what you want
lastEnteranceTime=Time.time;
}
}

You can use a variable instead of 10, however you can use exiting event if you don’t want to count the time that the object is within the zone so only set LastEnteranceTime at TriggerExit and change it’s name to something that shows it purpose in that case, Something like LastZoneExitTime.