Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HideObject : MonoBehaviour
- {
- public GameObject go;
- public string query;
- private List<GameObject> foundObjects;
- void Start(){
- this.foundObjects=this.FindRecursiveByName(this.query, this.go.transform);
- }
- public List<GameObject> FindRecursiveByName(string query, Transform parent)
- {
- Transform[] allChildren = go.GetComponentsInChildren<Transform>();
- List<GameObject> toret = new List<GameObject>();
- foreach (var t in allChildren)
- {
- if (t.name.Contains(query))
- {
- toret.Add(t.gameObject);
- ///Debug.Log(t.name);
- }
- Debug.Log("i got the renderer");
- }
- Debug.Log("there are " + toret.Count + " elements " + query + " " + parent);
- ///fin de boucle on a tous les éléments
- return toret;
- }
- public bool isAllOff=false;
- ///public void ToggleWalls()
- public void ToggleVisibilityOff()
- {
- isAllOff=!isAllOff;
- foreach(var res in foundObjects)
- {
- /*if (res.GetComponent<Renderer>() && res.GetComponent<Renderer>().enabled == true)
- {
- res.GetComponent<Renderer>().enabled = isAllOff;
- res.GetComponent<Collider>().enabled = isAllOff;
- }*/
- res.SetActive(isAllOff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement