using System.Collections; using System.Collections.Generic; using UnityEngine; public class TouchPlayAnimatior : MonoBehaviour { public HandFontSelfCtr showSelfFont; public GrabItem grabItem; Animator animator; AudioSource audioSource; //clips���� public AudioClip[] audioClips; //��ʱ��� bool isRun = false; float waitTime = 4f; float runTime = 0; float showGrabItem = 1.5f; //��ʾ����ͭ�ߵ�ʱ�� // Start is called before the first frame update void Start() { audioSource = GetComponent(); animator = GetComponent(); if (grabItem != null) grabItem.gameObject.SetActive(false); } private void Update() { if (isRun) { runTime += Time.deltaTime; if (runTime >= waitTime) { isRun = false; runTime = 0; ShowFont(); //if (grabItem != null) // grabItem.gameObject.SetActive(true); this.gameObject.SetActive(false); } if (runTime >= showGrabItem) //��ʾ�����ͭ�� { if (grabItem != null && grabItem.gameObject.activeSelf == false) { grabItem.gameObject.SetActive(true); PlayAudioByIndex(1); } } } } private void OnTriggerEnter(Collider other) { if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R") { this.GetComponent().enabled = false; animator.Play("Touch"); SetTriggerParameter("DisTrigger"); isRun = true; if (audioSource != null) PlayAudioByIndex(0); } } private void OnTriggerExit(Collider other) { if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R") { SceneMgr.Instance.isTrigger = false; } } [Header("��������")] [SerializeField] private GameObject childAnimator; // ֱ���϶��� public void SetTriggerParameter(string parameterName) { if (childAnimator != null) { childAnimator.transform.localScale = Vector3.zero; } } void ShowFont() { if (showSelfFont != null) showSelfFont.PlayShowJGWFont(); } public void PlayAudioByIndex(int index) { if (audioClips != null && index >= 0 && index < audioClips.Length) { if (audioClips[index] != null) { audioSource.clip = audioClips[index]; audioSource.Play(); } } else { Debug.LogWarning("��Ƶ����������Χ������Ϊ��"); } } }