How do I assign a variable to meshrenderers in children? c#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class equipGunScript : MonoBehaviour {
public Transform object1;
public Transform object2;
public float dist;
public bool gunEquipped;
public MeshRenderer iDontKnowWhatToCallThisVariable;
void Start () {
gunEquipped = false;
iDontKnowWhatToCallThisVariable = GetComponentInChildren ();
}
void Update () {
if (gunEquipped = false) {
toggleMeshInChildren (false);
} else {
toggleMeshInChildren (true);
}
dist = Vector3.Distance (object1.position, object2.position);
if (dist <= 1.5) {
if (Input.GetKeyDown (KeyCode.Mouse0)) {
gunEquipped = true;
}
}
}
void toggleMeshInChildren (bool a) {
transform.Find(“Child”).GetComponentInChildren().enabled = a;
}
}
//You dont won. Expect the unexpected.

If you are attempting to find multiple mesh renderers in children, then there is GetComponentsInChildren. This will return an array of all components found in the target. So for your needs, perhaps something like this:

public void ToggleRenderers(Transform lRoot, bool lEnabled)
{
	MeshRenderer[] lRenderers = lRoot.GetComponentsInChildren<MeshRenderer>();
	for (int i = 0; i < lRenderers.Length; i++)
	{
		lRenderers*.enabled = lEnabled;*
  • }*
    }
    Does this achieve what you are trying to do?