GetComponent for object in colider

so I’m making a game and I want to be able to mark objects with in a collider that is on my character with a bool on the object. but I don’t know how to change a bool from entering/exiting a collider and I don’t want it to start changing nonexistent bools from colliding with the ground.

all the objects have the same script with the bool and I only want objects with that script to interact with the collider.

@unity_768D2BA1044B8C76265C You can do this by

private void OnTriggerEnter(Collider other)
        if(other.TryGetComponent<YourScript>(out YourScript ys))
            ys.yourBool = true;