ChangeCamera.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Cinemachine;
  5. public class ChangeCamera : MonoBehaviour
  6. {
  7. private int _priority = 0;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. }
  12. private void OnTriggerEnter(Collider other)
  13. {
  14. Role role = other.gameObject.GetComponent<Role>();
  15. if(!role || !role.IsTeamLeader)
  16. {
  17. return;
  18. }
  19. CinemachineVirtualCamera cine = this.GetComponent<CinemachineVirtualCamera>();
  20. if(this._priority >= 100)
  21. {
  22. return;
  23. }
  24. this._priority = cine.Priority;
  25. cine.Priority += 100;
  26. }
  27. private void OnTriggerExit(Collider other)
  28. {
  29. Role role = other.gameObject.GetComponent<Role>();
  30. if (!role || !role.IsTeamLeader)
  31. {
  32. return;
  33. }
  34. CinemachineVirtualCamera cine = this.GetComponent<CinemachineVirtualCamera>();
  35. cine.Priority = this._priority;
  36. }
  37. }