feat(Console MovePlateform): 实现控制台和移动平台
This commit is contained in:
66
Assets/Script/Gameplay/Edit/MovingPlatformController.cs
Normal file
66
Assets/Script/Gameplay/Edit/MovingPlatformController.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Connect;
|
||||
using Script.Gameplay.Interface;
|
||||
|
||||
namespace Script.Gameplay.Edit
|
||||
{
|
||||
public class MovingPlatformController : MonoBehaviour, IEditableComponent, ISignalReceiver
|
||||
{
|
||||
[SerializeField] private GameObject startPositionObject;
|
||||
[SerializeField] private GameObject targetPositionObject;
|
||||
public float moveSpeed = 2f;
|
||||
private Vector3 startPosition;
|
||||
private Vector3 targetPosition;
|
||||
|
||||
private bool isMoving = false;
|
||||
private bool forward = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
startPosition = startPositionObject.transform.position;
|
||||
targetPosition = targetPositionObject.transform.position;
|
||||
transform.position = startPosition;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isMoving) return;
|
||||
|
||||
Vector3 destination = forward ? targetPosition : startPosition;
|
||||
transform.position = Vector3.MoveTowards(transform.position, destination, moveSpeed * Time.deltaTime);
|
||||
|
||||
if (Vector3.Distance(transform.position, destination) < 0.01f)
|
||||
{
|
||||
forward = !forward;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
isMoving = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isMoving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// IEditableComponent
|
||||
private bool isEditable = true;
|
||||
public bool IsComponentActive
|
||||
{
|
||||
get => isEditable;
|
||||
set
|
||||
{
|
||||
isEditable = value;
|
||||
isMoving = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ComponentName { get; set; } = "MovingPlatform";
|
||||
public LockLevel LockLevel => LockLevel.Red;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user