2025-04-16 19:57:54 -04:00
|
|
|
using UnityEngine; using Game; using Music; using Player;
|
|
|
|
|
namespace Game
|
|
|
|
|
{
|
2025-02-28 17:46:02 -05:00
|
|
|
|
|
|
|
|
public class MovingPlatform : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Transform platform;
|
|
|
|
|
public int startPoint;
|
|
|
|
|
public Transform[] points;
|
|
|
|
|
public float speed;
|
|
|
|
|
private int i;
|
|
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
void Start() // Sets the initial position of the platform
|
2025-02-28 17:46:02 -05:00
|
|
|
{
|
|
|
|
|
transform.position = points[startPoint].position;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-16 19:20:36 -04:00
|
|
|
void FixedUpdate()
|
2025-02-28 17:46:02 -05:00
|
|
|
{
|
2025-03-28 17:39:07 -04:00
|
|
|
// If the platform is close to the target point, it starts moving to the next one
|
2025-02-28 17:46:02 -05:00
|
|
|
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
if (i == points.Length)
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-28 17:39:07 -04:00
|
|
|
// Moves the platform towards the next point
|
2025-04-16 19:20:36 -04:00
|
|
|
// transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
|
|
|
|
|
GetComponent<Rigidbody2D>().MovePosition(Vector2.MoveTowards(transform.position, points[i].position, speed * Time.fixedDeltaTime));
|
2025-02-28 17:46:02 -05:00
|
|
|
}
|
2025-04-16 19:57:54 -04:00
|
|
|
}}
|