You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
837 B

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class ToggleChildren : MonoBehaviour {
  6. public KeyCode Key = KeyCode.F;
  7. // Use this for initialization
  8. GameObject[] Children=null;
  9. bool active=true;
  10. void OnEnable () {
  11. Children = new GameObject[gameObject.transform.childCount];
  12. for (int i = 0; i < gameObject.transform.childCount; i++)
  13. {
  14. Children[i] = gameObject.transform.GetChild(i).gameObject;
  15. }
  16. }
  17. // Update is called once per frame
  18. void Update () {
  19. if (Input.GetKeyDown(Key))
  20. {
  21. active = !active;
  22. for (int i = 0; i < gameObject.transform.childCount; i++)
  23. {
  24. Children[i].SetActive(active);
  25. }
  26. }
  27. }
  28. }