- Home /
Having an issue with procedural generation of obstacles
I was trying to spawn platforms every second, and it works once, but not after that. I have two empty gameObjects that are the instantiation points. Here is my script.
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class SpawnRandomPlatforms : MonoBehaviour
{ // Start is called before the first frame update public GameObject[] instantiated; public Transform playerPos; public Transform rightInstantiation; public Transform leftInstantiation; public float platformDistance; public int platforms; public bool isInstantiating = true; public int onethousand = 1000;
void Start()
{
while (isInstantiating == true)
{
platforms = Random.Range(0, 1);
GameObject InstantiatedPlatform = Instantiate(instantiated[platforms]);
isInstantiating = false;
StartCoroutine(DelayInstantiate());
Debug.Log("Has been insantiated " + platforms.ToString());
if (platforms == 0)
{
InstantiatedPlatform.transform.position = leftInstantiation.position;
//StartCoroutine(LeftPlatformDelay());
}
if (platforms == 1)
{
InstantiatedPlatform.transform.position = rightInstantiation.position;
//StartCoroutine(RightPlatformDelay());
}
}
}
IEnumerator DelayInstantiate()
{
yield return new WaitForSeconds(1f);
isInstantiating = true;
}
}
Answer by ethanol3310 · Mar 26, 2021 at 10:47 PM
Changed it to update and now it does it twice, but stops there
Your answer
Follow this Question
Related Questions
Best Solution For Procedural Match-3 Board? 0 Answers
How to darken a procedurally added texture (explained below) 0 Answers
How to instantiate prefabs in an unloaded (or just loaded) scene? 1 Answer
UV problem on procedural mesh generation 1 Answer
Modifying a procedural mesh using Lists is slow, what else can I use? 1 Answer