67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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;
|
|
}
|
|
}
|
|
|