neon_run/Assets/Scripts/SectionTriger.cs
2025-09-20 00:53:04 +05:30

36 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SectionTriger : MonoBehaviour
{
public static int counter =0;
public GameObject[] roadSection;
public float speed = -100f;
int headroom = 5;
void Start()
{
if(counter ==0){
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Trigger"))
{
int randomNumber = Random.Range(0, roadSection.Length);
if(counter == 0){
for(int i=0; i < headroom; i++){
Instantiate(roadSection[Random.Range(0, roadSection.Length)], new Vector3(0, 0, other.transform.position.z + (speed * (i+1))), Quaternion.identity);
}
}
Instantiate(roadSection[randomNumber], new Vector3(0, 0, other.transform.position.z + (speed * (headroom+1))), Quaternion.identity);
counter++;
}
}
}