ActivateOnKeypress.cs 908 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. public class ActivateOnKeypress : MonoBehaviour
  3. {
  4. public KeyCode ActivationKey = KeyCode.LeftControl;
  5. public int PriorityBoostAmount = 10;
  6. public GameObject Reticle;
  7. Cinemachine.CinemachineVirtualCameraBase vcam;
  8. bool boosted = false;
  9. void Start()
  10. {
  11. vcam = GetComponent<Cinemachine.CinemachineVirtualCameraBase>();
  12. }
  13. void Update()
  14. {
  15. if (vcam != null)
  16. {
  17. if (Input.GetKey(ActivationKey))
  18. {
  19. if (!boosted)
  20. {
  21. vcam.Priority += PriorityBoostAmount;
  22. boosted = true;
  23. }
  24. }
  25. else if (boosted)
  26. {
  27. vcam.Priority -= PriorityBoostAmount;
  28. boosted = false;
  29. }
  30. }
  31. if (Reticle != null)
  32. Reticle.SetActive(boosted);
  33. }
  34. }