AutoPlayLanterAnimation.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class AutoPlayLanterAnimation : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. }
  9. private IEnumerator PlayAnimation(float time)
  10. {
  11. yield return new WaitForSeconds(time);
  12. if (this.lanterAnimator != null)
  13. {
  14. this.lanterAnimator.speed = this.speed;
  15. this.lanterAnimator.Play("hit3");
  16. }
  17. float z = UnityEngine.Random.Range(-40f, 40f);
  18. if (this.light1Animator != null)
  19. {
  20. this.light1Animator.speed = this.speed;
  21. this.light1Animator.transform.rotation = Quaternion.Euler(0f, 0f, z);
  22. this.light1Animator.Play("lanternLight");
  23. }
  24. if (this.light2Animator != null)
  25. {
  26. this.light2Animator.speed = this.speed;
  27. this.light2Animator.transform.rotation = Quaternion.Euler(0f, 0f, z + UnityEngine.Random.Range(50f, 110f));
  28. this.light2Animator.Play("lanternLightAlter");
  29. }
  30. if (this.backgroundAnimator != null)
  31. {
  32. this.backgroundAnimator.speed = this.speed;
  33. this.backgroundAnimator.Play("lanternLightBackground");
  34. }
  35. yield break;
  36. }
  37. private void Update()
  38. {
  39. if (UnityEngine.Input.GetKeyDown(KeyCode.Space))
  40. {
  41. base.StartCoroutine(this.PlayAnimation(this.delay));
  42. }
  43. }
  44. public Animator lanterAnimator;
  45. public Animator light1Animator;
  46. public Animator light2Animator;
  47. public Animator backgroundAnimator;
  48. public float speed;
  49. public float delay;
  50. }