Hi,
I am creating an endlessruner. But I have a problem and I don’t know how to fix it anymore. I want the “Nitro” object to spawn along with the road, but in random places. As you can see in the video, it spawns only in the range of the Z axis (0.200) on the width of 579, 562. I do not understand why it does not appear in the next 200 meters on the Z axis together with the road. despite zPos + = 200;
OBJECT SPAWNING
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NitroSpawner : MonoBehaviour
{
public GameObject Nitro;
public int zPos = 200;
public bool creatingSection = false;
//random X i dodawanie Z
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
if (creatingSection == false)
{
creatingSection = true;
StartCoroutine(GenerateNitro()); // w corutine musi byc opóźneinie nie mozna tego zrobić w metodzie, opóznienie pojawiania sie mapy
}
}
IEnumerator GenerateNitro()
{
Instantiate(Nitro, new Vector3(Random.Range(579, 562), 305.5273f, Random.Range(0, 200)), Quaternion.Euler(0, 0, 0));
zPos += 200;
yield return new WaitForSeconds(1);
creatingSection = false;
}
}
ROAD SPAWNING
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateLevel : MonoBehaviour
{
public GameObject road;
public int zPos = 200;
public bool creatingSection = false;
void Update()
{
if (creatingSection == false)
{
creatingSection = true;
StartCoroutine(GenerateSection()); // w corutine musi byc opóźneinie nie mozna tego zrobić w metodzie, opóznienie pojawiania sie mapy
}
}
IEnumerator GenerateSection()
{
Instantiate(road, new Vector3(0, 0, zPos), Quaternion.Euler(0, 0, 0));
zPos +=200;
yield return new WaitForSeconds(1);
creatingSection = false;
}
}