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;
}
}