using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimatorControl : MonoBehaviour { public Animator animator; [Header("是否显示老师模型")] public bool modelActive; [Header("是否播放动画")] public bool animatonPlay; private AudioSource audioSource; private void Awake() { audioSource = GetComponent(); } private void OnEnable() { animator.gameObject.SetActive(modelActive); animator.SetBool("S1", false); animator.SetBool("S2", false); animator.SetBool("S3", false); animator.SetBool("Hold", false); if (animatonPlay) { animator.SetBool("S" + Random.Range(1, 4), true); } else { animator.SetBool("Hold", true); } StartCoroutine(Hold()); } void Start() { } private void OnDisable() { audioSource.Stop(); } private IEnumerator Hold() { yield return new WaitForSeconds(1); while (audioSource.isPlaying) { yield return null; } animator.SetBool("S1", false); animator.SetBool("S2", false); animator.SetBool("S3", false); animator.SetBool("Hold", true); } }