Search Unity

How to: find game object with tag in hierarchy and toggle mesh renderer

Discussion in 'Assets and Asset Store' started by xkingjohnx, Jan 19, 2021.

  1. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    Hi guys,

    I hope someone could help me a bit..
    I am trying to find runtime instatiated prefabs (clones) of a Game Object with a specific tag and than using the Toggle to turn off (and back on) the mesh renderer for these objects..

    I thought to make a empty game object and than add a script to that and than mapping the Script on the UI Toggle (On Value Changed Boolean and setting the GameObject to SetActive... but I have been only able to deactivate the object with this:


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Testing: MonoBehaviour
    5. {
    6.     GameObject[] MyTagObject;
    7.  
    8.     void Start()
    9.     {
    10.         Ceiling = GameObject.FindGameObjectsWithTag("MyTag");
    11.  
    12.         foreach (GameObject r in MyTagObject)
    13.         {
    14.             r.GetComponent<MeshRenderer>().enabled = false;
    15.             r.GetComponent<Collider>().enabled = false;
    16.         }

    I would very much appreciate if anyone would know how to toggle the mesh renderer back on with the toggle..

    any ideas?