How do I make a different interval for the appearance of balls?

  Kiến thức lập trình

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManagerX : MonoBehaviour
{
public GameObject[] ballPrefabs;

private float spawnLimitXLeft = -40;
private float spawnLimitXRight = 5;
private float spawnPosY = 30;

private float startDelay = 1.0f;
private float spawnInterval = 4;

// Start is called before the first frame update
void Start()
{
    InvokeRepeating("SpawnRandomBall", startDelay, spawnInterval);
}

// Spawn random ball at random x position at top of play area
void SpawnRandomBall ()
{
    // Generate random ball index and random spawn position
    Vector3 spawnPos = new Vector3(Random.Range(spawnLimitXLeft, spawnLimitXRight), spawnPosY, 0);

    // instantiate ball at random spawn location

    int ballIndex = Random.Range(0, ballPrefabs.Length);
    Instantiate(ballPrefabs[ballIndex], spawnPos, ballPrefabs[ballIndex].transform.rotation);
}

}
`

I need to make an appearance for example from 3 to 5 seconds, the Random.Range method does not work for some reason

New contributor

Юлиан is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT