Answer the question
In order to leave comments, you need to log in
How to make moving platforms?
I'm making a 2D platformer. I made a platform with such a script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterBehaviour : MonoBehaviour {
public float speed = 3f;
public Transform[] waypoints;
private int ArrayIndex;
void Start () {
ArrayIndex = 0;
}
void Update () {
transform.position = Vector2.MoveTowards (transform.position, waypoints[ArrayIndex].transform.position, speed * Time.deltaTime);
CheckWayPoint ();
}
void CheckWayPoint(){
int test = ArrayIndex + 1;
if (Vector2.Distance(transform.position,waypoints[ArrayIndex].transform.position)<0.1f) {
if (test > 1) {
ArrayIndex = 0;
} else {
ArrayIndex++;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question