KeyEnableBehaviors.cs 633 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Leap.Unity
  5. {
  6. public class KeyEnableBehaviors : 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 (Behaviour behaviour in this.targets)
  17. {
  18. MonoBehaviour monoBehaviour = (MonoBehaviour)behaviour;
  19. monoBehaviour.enabled = !monoBehaviour.enabled;
  20. }
  21. }
  22. }
  23. public List<Behaviour> targets;
  24. [Header("Controls")]
  25. public KeyCode unlockHold;
  26. public KeyCode toggle = KeyCode.Space;
  27. }
  28. }