How To Make Unity Level Object Spawner

Hi Can You Help ME To Create Unity Level Spawner. 20 Object To Spawn At Position 1s(0,0,20) 2nd(0,0,40)…

Get Object && Get SpawnCount.

Randomly spawn Object on 20 Position

if Level Restart Then load That same Level Again

Also Get Selected Object Set To Spawn On Different Level, Like 1 To 50,50 To 100;

Making Game For Android Iam New To Game Development 7 Days Iam Confused How To make this

Following Code Don’t Matter Just Example. Can Suggest Your Way How You will do this.

//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

 [System.Serializable]
public class ObjectToSpawn
{
    public GameObject Object;
    public int spawnCount;

}

public class LevelSpawner : MonoBehaviour
{

    public Transform[] SpawnLocation; //Obstacles Spawn Location
    public ObjectToSpawn[] itemToSpawn; // Select Obstacles For spawn
    public int maxSpawnObject;  // Total Object
    private Vector3[] LastSpawnLocation;  //  if Level Restart Spawn Last Object And Its 
}

// Another

[System.Serializable]
public class LevelSelection
{

    public string Element; // Selected List Of Object And Count For Spawn
    public int LevelFrom;
    public int LevelTo;


}

public class ObjectSelect : MonoBehaviour
{

    public LevelSpawner[] SetOfLevel;  //Get Selected Object To spawn
    public LevelSelection[] levelselection; //
}
    ![188203-how2.png|311x490](upload://2ttGWxJkCq0tQopLgk3ystzLrhZ.png)

you could have made this extremely simple way.

  1. make a level sector function(make sure to add “_selectedLevelIndex” int variable)
  2. make a new empty scene for the game
  3. make empty gameObject
  4. into that empty gameObject add all the levels you wanted to add
  5. make a script add that to the empty game object that has all the levels inside as a child
  6. make that script responsible for enabling only one Level. that is based on “_selectedLevelIndex” and disable other remaining levels.

pros:

  1. super simple to add this type of function
  2. it will not use any type of instantiation function
  3. performance cost will be lower and you will get like 2X more fps depending on the game.
  4. you don’t have to make a separate scene for every Level
  5. overall game size will be lower

cons:

  1. take sometime’s to implement