AnimatorControl.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class AnimatorControl : MonoBehaviour
  5. {
  6. public Animator animator;
  7. [Header("是否显示老师模型")]
  8. public bool modelActive;
  9. [Header("是否播放动画")]
  10. public bool animatonPlay;
  11. private AudioSource audioSource;
  12. void Start()
  13. {
  14. audioSource = GetComponent<AudioSource>();
  15. animator.gameObject.SetActive(modelActive);
  16. animator.SetBool("S1", false);
  17. animator.SetBool("S2", false);
  18. animator.SetBool("S3", false);
  19. animator.SetBool("Hold", false);
  20. if (animatonPlay)
  21. {
  22. animator.SetBool("S" + Random.Range(1, 4), true);
  23. }
  24. else
  25. {
  26. animator.SetBool("Hold", true);
  27. }
  28. StartCoroutine(Hold());
  29. }
  30. private IEnumerator Hold()
  31. {
  32. yield return new WaitForSeconds(1);
  33. while (audioSource.isPlaying)
  34. {
  35. yield return null;
  36. }
  37. animator.SetBool("S1", false);
  38. animator.SetBool("S2", false);
  39. animator.SetBool("S3", false);
  40. animator.SetBool("Hold", true);
  41. }
  42. }
粤ICP备19079148号