Files
PrinceOfGlory/Assets/Scripts/Scene_05/TouchPlayAnimatior.cs
kridoo 6bcbc56c2d 1
2025-11-17 17:25:11 +08:00

108 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchPlayAnimatior : MonoBehaviour
{
public HandFontSelfCtr showSelfFont;
public GrabItem grabItem;
Animator animator;
AudioSource audioSource;
//clips<70><73><EFBFBD><EFBFBD>
public AudioClip[] audioClips;
//<2F><>ʱ<EFBFBD><CAB1><EFBFBD>
bool isRun = false;
float waitTime = 4f;
float runTime = 0;
float showGrabItem = 1.5f; //<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ͭ<EFBFBD>ߵ<EFBFBD>ʱ<EFBFBD><CAB1>
// 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) //<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ͭ<EFBFBD><CDAD>
{
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);
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R")
{
SceneMgr.Instance.isTrigger = false;
}
}
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
[SerializeField] private GameObject childAnimator; // ֱ<><D6B1><EFBFBD>϶<EFBFBD><CFB6><EFBFBD>
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("<22><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>");
}
}
}