Enable/disable mesh renderer component of a child

I have searched everywhere but I can’t figure out how to enable/disable the Meshrenderer of a child.

I have tried to use gameObject, GameObject (now I’ve used transform instead), but my inexperience and little coding knowledge is letting me down.

Here’s a piece of my code so far that could be relevant, search for void Start:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CharacterSelect : MonoBehaviour {
	
	bool isSelected = false;
	Vector3 targetPos;
	Ray ray;
	RaycastHit hit;
	BunnyAttack bunnyattack;
	public float distanceFromTarget;
	public List<GameObject> bears; 
	public Transform selected;

	void Start ()
	{
	selected = transform.Find("Selected");
	selected.GetComponent(MeshRenderer).enabled = false;

Hey there,

I just opened a new scene, created an empty game object, parented a cube object named “Child” to it and put a test script on the parent object with the following code and it worked. Here’s the sample :

public class test : MonoBehaviour {

	// Use this for initialization
	void Start () {
		transform.Find("Child").GetComponent<MeshRenderer>().enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Maybe you are always enabling it in an update in another script or something.

Hope it helped.

Instead of this line:
selected.GetComponent(MeshRenderer).enabled = false;

Use
selected.renderer.enabled= false;