I have a road system for and endless driver game. The road sections have colliders to move it to the end and keep it going on and on. I have pickups that have a collider on them so they will add points and destroy. When I drive through, the pickup disappears and so does the road section I am driving on. If I avoid the pickup, the road section stays and functions properly. The roads are under an empty. The pickups are under another empty. each has their own script. I will post the pick up script first. The two scripts for the road section will be second and third. TIA.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CandyScript : MonoBehaviour
{
private BoxCollider candyCorn;
void Start()
{
candyCorn = GameObject.Find(“candycorn”).GetComponent();
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, 90 * Time.deltaTime, 0);
}
private void OnTriggerEnter(Collider other)
{
if(other.name == “Player”)
{
other.GetComponent ().points++;
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class RoadSpawner : MonoBehaviour
{
public List roads;
private float offset = 80f;
void Start()
{
if(roads != null && roads.Count > 0)
{
roads = roads.OrderBy(r => r.transform.position.z).ToList();
}
}
public void MoveRoad()
{
GameObject moveRoad = roads[0];
roads.Remove(moveRoad);
float newZ = roads[roads.Count - 1].transform.position.z + offset;
moveRoad.transform.position = new Vector3(0, 0, newZ);
roads.Add(moveRoad);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
RoadSpawner roadSpawner;
// Start is called before the first frame update
void Start()
{
roadSpawner = GetComponent();
}
// Update is called once per frame
void Update()
{
}
public void SpawnTriggerEntered()
{
roadSpawner.MoveRoad();
}
}