I about to go nuts trying to figure out why my MovingPlatform script won’t actually pause/delay.
I get no errors, and my Debug.Log info executes correctly, but my platform is NOT delaying when moving from one Waypoint to another.
What am I missing?
***HELP PART 2: I want to move the “delayTimer” and actually add it to each Transform that is created from the line “public Transform Waypoints;” Is there a way to do that? That way, the user could add a delay to some waypoints, and leave some at 0.
ANYWAY… Thank you for looking and helping me understand where my brain is failing me =)
using UnityEngine;
using System.Collections;
public class MovingPlatform : MonoBehaviour
{
public Transform[] Waypoints;
public float moveSpeed = 3;
public float rotateSpeed = 0.5f;
public float scaleSpeed = 0.5f;
public float delayTimer = 3;
public int CurrentPoint = 0;
IEnumerator timeToDelay()
{
Debug.Log("Delay timer activated...");
yield return new WaitForSeconds(delayTimer);
Debug.Log("Delay timer completed!");
}
void FixedUpdate ()
{
if (transform.position != Waypoints [CurrentPoint].transform.position)
{
transform.position = Vector3.MoveTowards (transform.position, Waypoints [CurrentPoint].transform.position, moveSpeed * Time.deltaTime);
transform.rotation = Quaternion.Lerp (transform.rotation, Waypoints [CurrentPoint].transform.rotation, rotateSpeed * Time.deltaTime);
transform.localScale = Vector3.Lerp (transform.localScale, Waypoints [CurrentPoint].transform.localScale, scaleSpeed * Time.deltaTime);
}
if (transform.position == Waypoints [CurrentPoint].transform.position)
{
StartCoroutine(timeToDelay());
CurrentPoint += 1;
}
if( CurrentPoint >= Waypoints.Length)
{
CurrentPoint = 0;
}
}
}