KeyEnableGameObjects.cs 592 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Leap.Unity
  5. {
  6. public class KeyEnableGameObjects : MonoBehaviour
  7. {
  8. private void Update()
  9. {
  10. if (this.unlockHold != KeyCode.None && !Input.GetKey(this.unlockHold))
  11. {
  12. return;
  13. }
  14. if (Input.GetKeyDown(this.toggle))
  15. {
  16. foreach (GameObject gameObject in this.targets)
  17. {
  18. gameObject.SetActive(!gameObject.activeSelf);
  19. }
  20. }
  21. }
  22. public List<GameObject> targets;
  23. [Header("Controls")]
  24. public KeyCode unlockHold = KeyCode.RightShift;
  25. public KeyCode toggle = KeyCode.T;
  26. }
  27. }