enabling a script by entering a trigger

Sorry in advance ,I looked all day in Unity Answers and on the forums but could not find the answer I’m looking for.

All I want to do is activate a script that is attached to an object when the player enters the trigger, and disable it when the player leaves the trigger.

I’ve tried various scripts that seemed close to what I needed to do ,but got compiler errors when I tried them.

Can anyone help me please?

i think that would be something like:

void OnTriggerEnter(Collision other)
{
    if (other.gameObject.tag == "Player")
    {
        MyScript myScript = other.gameObject.GetComponent<MyScript>();
        //You could check if you really attached MyScript here, but I think we skip that. ;-)
        myScript.enabled = true;
    }
}

void OnTriggerExit(Collision other)
{
    if (other.gameObject.tag == "Player")
    {
        MyScript myScript = other.gameObject.GetComponent<MyScript>();
        myScript.enabled = false;
    }
}

It only Works if the script you’re trying to manipulate is attached to the player.