2023-05-16 18:24:31 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class MovingPlatform : MonoBehaviour
|
|
|
|
{
|
|
|
|
public float speed;
|
|
|
|
public int startingPoint;
|
|
|
|
public Transform[] points;
|
|
|
|
private int i;
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
transform.position = points[startingPoint].position;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (Vector2.Distance(transform.position, points[i].position)<0.02f)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
if(i==points.Length)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
|
|
|
|
}
|
2023-05-20 17:35:54 +02:00
|
|
|
|
|
|
|
private void OnCollisionEnter2D(Collision2D coll)
|
|
|
|
{
|
|
|
|
coll.transform.SetParent(transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnCollisionExit2D(Collision2D coll)
|
|
|
|
{
|
|
|
|
coll.transform.SetParent(null);
|
|
|
|
}
|
2023-05-16 18:24:31 +02:00
|
|
|
}
|