Hey, I need to toggle multiple Mesh Renderer which are all children of an game object per MouseDown.
Here you can see a picture of my scene:
All the houses on the tables should disappear if I click on one of them. I tried to find a solution for several hours now and came up with this script:
using UnityEngine;
using System.Collections;
public class clickonoffmulti : MonoBehaviour
{
void OnMouseDown()
{
gameObject.GetComponentInChildren<Renderer>().enabled = !gameObject.GetComponentInChildren<Renderer>().enabled;
}
}
For that, I put all the houses as children under a simple cube (as hitbox for clicking), but only the Mesh Renderer of the cube itself turns on and off. Is there a way to click on any of the houses and turn them all on and off at the same time? where should I place the script for that purpose?
Sorry for my noob question, I started with C# in Unity just some days ago;)