Trying to deactivate a script when I'm not in the collider area

I want to deactivate the script when I’m not on the area of the collider, when I enter to the area, it activate and that’s ok but when I leave the area still are activate. This is my script:

    public GameObject car;
	autoTeletransport script;

	void Start ()
	{
		script = car.GetComponent<autoTeletransport> ();
		script.enabled = false;
	}

	void OnTriggerEnter (Collider col)
	{
		if (col.gameObject.tag == "Player") //When I enter in the collider area
		{
			if (script.enabled == false) 
			{
				script.enabled = true;
			} 
		} 
		else if (col.gameObject.tag != "Player") //When I leave the collider area but the script didn't stop it
		{
			if (script.enabled == true) 
			{
				script.enabled = false;
			} 
		}
	}
}

Sorry for my bad english. Thanks

Hey I see your reasoning here, but it’s important to note that OnTriggerEnter only fires when the trigger is first entered by an object. Therefore, it runs once and it’s done.

Fortunately, there’s a handy OnTriggerExit function.

void OnTriggerExit (Collider col)
     {
         if (col.gameObject.tag == "Player") //When I enter in the collider area
         {
             if (script.enabled == true) 
             {
                 script.enabled = false;
             } 
         } 

Hope this helps! :slight_smile: