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.