AnimatorControl.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. private void Awake()
  13. {
  14. audioSource = GetComponent<AudioSource>();
  15. }
  16. private void OnEnable()
  17. {
  18. animator.gameObject.SetActive(modelActive);
  19. animator.SetBool("S1", false);
  20. animator.SetBool("S2", false);
  21. animator.SetBool("S3", false);
  22. animator.SetBool("Hold", false);
  23. if (animatonPlay)
  24. {
  25. animator.SetBool("S" + Random.Range(1, 4), true);
  26. }
  27. else
  28. {
  29. animator.SetBool("Hold", true);
  30. }
  31. StartCoroutine(Hold());
  32. }
  33. void Start()
  34. {
  35. }
  36. private void OnDisable()
  37. {
  38. audioSource.Stop();
  39. }
  40. private IEnumerator Hold()
  41. {
  42. yield return new WaitForSeconds(1);
  43. while (audioSource.isPlaying)
  44. {
  45. yield return null;
  46. }
  47. animator.SetBool("S1", false);
  48. animator.SetBool("S2", false);
  49. animator.SetBool("S3", false);
  50. animator.SetBool("Hold", true);
  51. }
  52. }
粤ICP备19079148号