Toggle between to active gameobjects while child's only activate when the parent is clicked using c#??

so basically i need help with the deactivating part i can select the gameobjects just fine and show the child of those game objects but they continue to show at the same time if u don’t click it again before selecting the next object. so basically i need it to be if B is selected A unselected and vise versa.

public static Component Play1;
public static Component Play2;
public GameObject[] Player = new GameObject [7];

void OnMouseEnter ()
{
	//change text color
	renderer.material.color = Color.black;
}

void OnMouseExit ()
{
	//change text color
	renderer.material.color = Color.white;
}

void OnMouseDown()
{
	for (int i = 0; i < Player.Length; i++) {
		if (Player *) {*

Player .SetActive (!Player .activeSelf);
* }*
* }*
* }*
}

I tend to avoid static variables in general. But I they seem to be a good way to communicate between different objects in the same class, often producing cleaner solutions than the alternatives. So for your code, you can do something like this:

public static Component Play1;
public static Component Play2;
public GameObject[] Player = new GameObject [7];

private static GameObject goSelected = null;
private bool selected = false;

void Update() {
	if (selected && goSelected != gameObject) {
		for (int i = 0; i < Player.Length; i++) {
			if (Player *) {*

_ Player .SetActive (false);_
* }*
* }*
* selected = false;*
* }*
* }*

* void OnMouseEnter ()*
* {*
* //change text color*
* renderer.material.color = Color.black;*
* }*

* void OnMouseExit ()*
* {*
* //change text color*
* renderer.material.color = Color.white;*
* }*

* void OnMouseDown()*
* {*
* for (int i = 0; i < Player.Length; i++) {*
_ if (Player ) {
Player .SetActive (true);
* }
}
goSelected = gameObject;
selected = true;
}*_