GenericTrigger.cs 843 B

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