99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
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<AudioSource>();
|
|
animator = GetComponent<Animator>();
|
|
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<BoxCollider>().enabled = false;
|
|
animator.Play("Touch");
|
|
SetTriggerParameter("DisTrigger");
|
|
isRun = true;
|
|
if (audioSource != null)
|
|
PlayAudioByIndex(0);
|
|
}
|
|
}
|
|
[Header("动画控制")]
|
|
[SerializeField] private Animator childAnimator; // 直接拖动绑定
|
|
|
|
public void SetTriggerParameter(string parameterName)
|
|
{
|
|
if (childAnimator != null)
|
|
{
|
|
childAnimator.SetTrigger(parameterName);
|
|
}
|
|
}
|
|
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("音频索引超出范围或数组为空");
|
|
}
|
|
}
|
|
|
|
}
|