ActivateOnKeypress.cs 1.2 KB

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