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