I am trying to create a program that will spawn balls from the top randomly at random times. The problem is it is not fast enough, but if I change the value to like 1/2 it spawns 50 super fast.
using System.Collections.Generic;
using UnityEngine;
public class SpawnAstroids : MonoBehaviour
{
public GameObject astriod;
public float xBounds, yBounds;
public int playerPoints = 0;
public int enemyPoints = 0;
void Start()
{
StartCoroutine(SpawnRandomGameObject());
}
IEnumerator SpawnRandomGameObject()
{
yield return new WaitForSeconds(Random.Range(1,2)); //Random.Range(1/2, 2)
Instantiate(astriod, new Vector2(Random.Range(-xBounds, xBounds), yBounds), Quaternion.identity);
StartCoroutine(SpawnRandomGameObject());
}
}
CodePudding user response:
Unity requires that you specify whether your decimal is specifically a float or a double. Add in f
to the end of each decimal number. For example: Random.Range(0.5f, 2)
;