GenericTrigger.cs 981 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #if CINEMACHINE_TIMELINE
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. namespace Cinemachine.Examples
  5. {
  6. public class GenericTrigger : MonoBehaviour
  7. {
  8. public PlayableDirector timeline;
  9. // Use this for initialization
  10. void Start()
  11. {
  12. timeline = GetComponent<PlayableDirector>();
  13. }
  14. void OnTriggerExit(Collider c)
  15. {
  16. if (c.gameObject.CompareTag("Player"))
  17. {
  18. // Jump to the end of the timeline where the blend happens
  19. // This value (in seconds) needs to be adjusted as needed if the timeline is modified
  20. timeline.time = 27;
  21. }
  22. }
  23. void OnTriggerEnter(Collider c)
  24. {
  25. if (c.gameObject.CompareTag("Player"))
  26. {
  27. timeline.Stop(); // Make sure the timeline is stopped before starting it
  28. timeline.Play();
  29. }
  30. }
  31. }
  32. }
  33. #endif