feat():完成天核的开合
This commit is contained in:
46
Assets/Script/Gameplay/Facility/TianHeController.cs
Normal file
46
Assets/Script/Gameplay/Facility/TianHeController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class TianHeController : BaseFacilityController
|
||||
{
|
||||
[SerializeField] private GameObject lidPrefab;
|
||||
[SerializeField] private AudioClip openSound;
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
|
||||
private Coroutine lidCoroutine;
|
||||
[SerializeField] private Vector3 closedPos = new Vector3(0f, 0f, 0f);
|
||||
[SerializeField] private Vector3 openPos = new Vector3(0f, 0.5f, 0f);
|
||||
[SerializeField] private float lidMoveDuration = 1f; // 盖子动画时长
|
||||
|
||||
public override void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
base.OnSignalReceived(active, sender);
|
||||
// 停止之前的动画
|
||||
if (lidCoroutine != null)
|
||||
StopCoroutine(lidCoroutine);
|
||||
// 启动新的动画
|
||||
lidCoroutine = StartCoroutine(MoveLid(active ? openPos : closedPos));
|
||||
if (audioSource != null && openSound != null && active)
|
||||
{
|
||||
audioSource.clip = openSound;
|
||||
audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator MoveLid(Vector3 targetPos)
|
||||
{
|
||||
Vector3 startPos = lidPrefab.transform.localPosition;
|
||||
float elapsed = 0f;
|
||||
while (elapsed < lidMoveDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
lidPrefab.transform.localPosition = Vector3.Lerp(startPos, targetPos, elapsed / lidMoveDuration);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
lidPrefab.transform.localPosition = targetPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Script/Gameplay/Facility/TianHeController.cs.meta
Normal file
3
Assets/Script/Gameplay/Facility/TianHeController.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8f77d0a85f044dcb710f54ed56f5479
|
||||
timeCreated: 1761745727
|
||||
Reference in New Issue
Block a user