How do I change a GO's component from another GO?

I have objects in my sphere game that have GravityAttractors attached to them. I need to have other objects assign their own GravityAttractors to the players GravityAttractor, replacing the player’s original. Essentially, when the player gets close to an object, their gravity source changes to the new, closer object. How do I do that?

On the player object, I have this:

public GravityAttractor attractor;    

On another object, I have this:

    public GameObject player;
    public GravityAttractor myAttractor;
    public GravityAttractor playerGravAttractor;

    private void Start()
    {
        GravityAttractor playerGravAttractor = player.GetComponent(typeof(GravityAttractor)) as GravityAttractor;
    }

Then when the player enters the collider, their GravityAttractor should switch to the new one. So on the object they encounter, I have this

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "Player")
        playerGravAttractor = player.GetComponent(typeof(GravityAttractor)) as GravityAttractor;
}

But I don’t know the next step on how to assign the object’s GravityAttractor to the player’s.

On the player, you add a public method to designate the new attractor:

public class PlayerController : MonoBehaviour
{
	private GravityAttractor attractor;

	public void SetGravityAttractor(GravityAttractor _attractor)
	{
		attractor = _attractor;
	}
}

On the object with the collider :

public class ObjectController : MonoBehaviour
{
	[SerializeField] private PlayerController player;

	public GravityAttractor myAttractor; // Probably can be private.    

	private void OnTriggerEnter (Collider other)
	{
		if (other.gameObject.CompareTag ("Player"))
		{
			player.SetGravityAttractor (myAttractor);
		}
	}
}