Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MovingPlatform : MonoBehaviour
- {
- public GameObject platform;// Reference to the platform object
- public float moveSpeed;// Speed at which the platform moves
- public Transform currentPoint;// Reference to the current point
- public Transform[] points;// Reference to the points array
- public int pointSelection;// Reference to the point selection
- // Start is called before the first frame update
- void Start()
- {
- currentPoint = points[pointSelection];// Set the current point to the first point in the points array
- }
- // Update is called once per frame
- void Update()
- {
- platform.transform.position = Vector3.MoveTowards(platform.transform.position, currentPoint.position, Time.deltaTime * moveSpeed );// Move the platform towards the current point
- if (platform.transform.position == currentPoint.position)// If the platform has reached the current point
- {
- pointSelection++;// Increment the point selection
- if (pointSelection == points.Length)// If the point selection is equal to the length of the points array
- {
- pointSelection = 0;// Set the point selection to 0
- }
- currentPoint = points[pointSelection];// Set the current point to the next point in the points array
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement