using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trackhandler : MonoBehaviour
{
[SerializeField] float movespeed = 0f;
[SerializeField] float Distance = -100f;
public GameObject trackpre;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
gameObject.transform.Translate(-Vector3.forward * movespeed * Time.deltaTime);
if(gameObject.transform.position.z <= Distance)
{
Destroy(gameObject.transform.GetChild(0).gameObject);
Distance = Distance - 50;
GameObject temp = Instantiate(trackpre,Vector3.zero, Quaternion.identity);
temp.transform.position = new Vector3(0, 0, gameObject.transform.GetChild(gameObject.transform.childCount - 1).transform.position.z + 20);
temp.transform.parent = gameObject.transform;
}
}
}
i have been trying to wrap around my head in this script but i can’t seem to understand it even a bit, i just started coding inside unity and i would appreciate the help in understanding the code. Here i am trying to move the object towards the player and after certain distance the first tile will be destroyed and will be created at the end of the remaining tiles.TIA