I found a tutorial for moving platforms as well as sticking to them and I wrote the script exactly as they did, but my platform is going to a spot that was never called from my Position 1/2 variables.
using UnityEngine;
using System.Collections;
public class MovingPlatform : MonoBehaviour {
public Transform movingPlatform;
public Transform position1;
public Transform position2;
public Vector3 newPosition;
public string currentState;
public float smooth;
public float resetTime;
void FixedUpdate(){
movingPlatform.position = Vector3.Lerp (movingPlatform.position, newPosition, smooth * Time.deltaTime);
}
void ChangeTarget(){
if (currentState == "Moving To Position 1") {
currentState = "Moving To Position 2";
newPosition = position2.position;
}
else if (currentState == "Moving To Position 2") {
currentState = "Moving To Position 1";
newPosition = position1.position;
}
else if (currentState == "") {
currentState = "Moving To Position 2";
newPosition = position2.position;
}
Invoke ("ChangeTarget", resetTime);
}
}
Instead of it going between my Position 1 and Position 2 transforms, the platform just moves as if I sent it somewhere unspecified.
I used this video. I used a 3D example for something else and just changed around some 2D code, but I am not sure what I am missing with this.