Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HideObject : MonoBehaviour
  6. {
  7.     public GameObject go;
  8.     public string query;
  9.    
  10.     private List<GameObject> foundObjects;
  11.  
  12.     void Start(){
  13.         this.foundObjects=this.FindRecursiveByName(this.query, this.go.transform);
  14.     }
  15.     public List<GameObject> FindRecursiveByName(string query, Transform parent)
  16.     {
  17.         Transform[] allChildren = go.GetComponentsInChildren<Transform>();
  18.         List<GameObject> toret = new List<GameObject>();
  19.         foreach (var t in allChildren)
  20.         {
  21.             if (t.name.Contains(query))
  22.             {
  23.                 toret.Add(t.gameObject);
  24.                 ///Debug.Log(t.name);
  25.             }
  26.            
  27.             Debug.Log("i got the renderer");
  28.  
  29.  
  30.         }
  31.         Debug.Log("there are " + toret.Count + " elements " + query + " " + parent);
  32.         ///fin de boucle on a tous les éléments
  33.         return toret;
  34.     }
  35.    
  36.     public bool isAllOff=false;
  37.  
  38.     ///public void ToggleWalls()
  39.     public void ToggleVisibilityOff()
  40.     {
  41.         isAllOff=!isAllOff;
  42.  
  43.         foreach(var res in foundObjects)
  44.         {
  45.             /*if (res.GetComponent<Renderer>() && res.GetComponent<Renderer>().enabled == true)
  46.             {
  47.                 res.GetComponent<Renderer>().enabled = isAllOff;
  48.                 res.GetComponent<Collider>().enabled = isAllOff;
  49.             }*/
  50.             res.SetActive(isAllOff);
  51.         }
  52.                
  53.  
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement