How to turn turn off/on a collider with a boolean from another script

Hi, I’m rather new to unity and C#.

I am trying to set up something that will allow me to toggle a material assigned to a box collider on/ off.

Basically I have a boolean variable assigned to my Player called IsBlue.
I then have a box collider assigned to my Ground object. Within this box collider I have assigned a material which will make my player bounce when in contact with it.

What I want to do is switch these bouncing physics on/off depending on if my IsBlue variable is set to true or not.

For example If IsBlue is set to false then the box collider should be enabled. If IsBlue = True then the box collider should be disbaled.

I’m pretty sure this is a simple task however i’m new to C# and can’t make sense of anything I’ve found online. There seems to be examples but no explanation of how to use the example.

I understand the concept of coding but am unfamilliar with the syntax. I essentially need to know:
How to reference the IsBlue Bool from my other Player.cs Script and how to then create an if Statment to get the results above.

Could anyone help?

Thanks.

Not tested, but something like this should do it. (I would change the variable name of isBlue to blue)

Ground Class:

private BoxCollider boxCollider;
private Player player;

void Sart ()
{
  boxCollider = GetComponent<BoxCollider> ();
  player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Player> ();
}

void Update ()
{
  // check if the player is blue and do something
  if (player.isBlue ()) {
    boxCollider.enabled = false;
  }
  else {
     boxCollider.enabled = true;
  }
}

Player Class:

private bool blue;

void Start ()
{
  // whatever the initial blue value should be
  blue = true;
}

public bool isBlue ()
{
  return blue;
}