using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Collections; public class Platformer : MonoBehaviour { public GameObject Platform; [Header("Set the stopping points of the platform")] public GameObject[] Stop_points; [Header("Set the platform's speed")] public float PlatformSpeed = 0.4f; [Header("How long will the platform remain still")] public float timeBetweenStops = 0; [Header("Should the platform reverse it's path on reching the last point or should it keep going?")] public bool Reverse_Path_On_Conclussion = true; ////Internal values private int Current_Target = 0; private bool Reversing_Path = false; private bool stopped = false; ////////////////////////////////////////////////////////// /////////// ///////// /////////// /// /// /// /// /// /// /////////// /// /////////// /// /// /// /// /// /// /////////// ///////// /////////// ////////////////////////////////////////////////////////// void FixedUpdate(){ if(stopped==false){ if(Vector3.Distance(Stop_points[Current_Target].transform.position, Platform.transform.position)<0.01f){ stopped=true; StartCoroutine(_Time_Between_Movements()); } else{ Platform.transform.position = Vector3.MoveTowards(Platform.transform.position, Stop_points[Current_Target].transform.position, PlatformSpeed* Time.deltaTime); } } } private IEnumerator _Time_Between_Movements(){ if(Stop_points!=null && Stop_points.Length>0){ if(Reverse_Path_On_Conclussion){/////REVERSIBLE PATH MODE if(Reversing_Path){///REVERSE PATHING ///CHECK IF IT REACHED THE BEGINNING OF THE LINE if(Current_Target-1 <= 0){ Reversing_Path = false; } Current_Target--; } else{///NORMAL PATHING ///CHECK IF IT REACHED THE END OF THE LINE if(Current_Target+1>=Stop_points.Length-1){ Reversing_Path = true; } Current_Target++; } } else{ ///CHECK IF IT REACHED THE END OF THE LINE if(Current_Target+1>=Stop_points.Length){ Current_Target = 0; } else{ Current_Target++; } } } yield return new WaitForSeconds(timeBetweenStops); stopped=false; } }