Files
2025TapTapGameJam/Assets/Script/Gameplay/Facility/PressurePlateController.cs

49 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEngine;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
{
public class PressurePlateController : BaseFacilityController
{
[SerializeField] private LayerMask detectLayer = ~0; // 检测所有层可在Inspector中指定
[SerializeField] private Vector3 plateSize = new Vector3(1, 0.2f, 1);
[SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f;
[SerializeField] private GameObject pressTopPrefab;
private bool lastState = false;
private bool hasObject = false;
private void FixedUpdate()
{
2025-10-23 09:26:47 +08:00
if (!isOpenInEditor) return;
2025-10-29 12:48:44 +08:00
hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity,
detectLayer);
if (hasObject != lastState)
{
SendSignal(hasObject, this.gameObject);
lastState = hasObject;
if (hasObject)
{
// 被压下动画
2025-10-29 12:48:44 +08:00
if (pressTopPrefab != null)
pressTopPrefab.transform.localPosition = new Vector3(0, 0, 0.1f);
}
else
{
// 弹起动画
2025-10-29 12:48:44 +08:00
if (pressTopPrefab != null)
pressTopPrefab.transform.localPosition = new Vector3(0, 0, 1);
}
}
}
2025-10-29 12:48:44 +08:00
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position + plateOffset, plateSize);
}
#endif
}
}