1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections.Generic;
- using UnityEngine;
- public class TurnOnOffTimePeriod : MonoBehaviour
- {
- public bool year2019 = false, year2020 = false, year2021 = false;
- private List<Component> humansBody2019 = new List<Component>();
- private List<Component> humansBody2020 = new List<Component>();
- private List<Component> humansBody2021 = new List<Component>();
-
- void Start()
- {
- Component[] obj = GetComponentsInChildren<Transform>(true);
- foreach (Transform child in obj)
- {
- if (child.parent == obj[0])
- continue;
- if (child.CompareTag("2019"))
- {
- humansBody2019.Add(child);
- if(!year2019)
- year2019 = child.gameObject.activeSelf;
- }
- else if (child.CompareTag("2020"))
- {
- humansBody2020.Add(child);
- if(!year2020)
- year2020 = child.gameObject.activeSelf;
- }
- else if(child.CompareTag("2021"))
- {
- humansBody2021.Add(child);
- if(!year2021)
- year2021 = child.gameObject.activeSelf;
- }
- }
- }
- private void Update()
- {
- if (year2019 == true)
- changeVisibility(humansBody2019, true);
- else
- changeVisibility(humansBody2019, false);
- if (year2020 == true)
- changeVisibility(humansBody2020, true);
- else
- changeVisibility(humansBody2020, false);
- if (year2021 == true)
- changeVisibility(humansBody2021, true);
- else
- changeVisibility(humansBody2021, false);
- }
- private void changeVisibility(List<Component> humansBodies, bool activeStatus)
- {
- foreach (Transform humanBody in humansBodies)
- foreach (Transform child in humanBody)
- child.gameObject.SetActive(activeStatus);
- }
- }
|