using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Platform : MonoBehaviour
{
    public BoxCollider area;

    private Vector3 lastPosition;

    private void Start()
    {
        lastPosition = transform.position;
    }

    private void LateUpdate()
    {
        var delta = transform.position - lastPosition;
        if (delta.magnitude > 0)
        {
            var cols = Physics.OverlapBox(area.transform.position, area.size / 2f);
            foreach (var col in cols)
            {
                if (col.attachedRigidbody != null && !col.attachedRigidbody.isKinematic)
                {
                    col.attachedRigidbody.position += delta;
                }
            }
        }
        lastPosition = transform.position;
    }
}
