| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AnimatorControl : MonoBehaviour
- {
- public Animator animator;
- [Header("是否显示老师模型")]
- public bool modelActive;
- [Header("是否播放动画")]
- public bool animatonPlay;
- [Header("结束时是否显示老师模型")]
- public bool modelEndActive = true;
- private AudioSource audioSource;
- private void Awake()
- {
- audioSource = GetComponent<AudioSource>();
- }
- 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();
- animator.SetBool("S1", false);
- animator.SetBool("S2", false);
- animator.SetBool("S3", false);
- animator.SetBool("Hold", true);
- if (!modelEndActive)
- {
- animator.gameObject.SetActive(false);
- }
- }
- 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);
- }
- }
|