Created
December 16, 2022 21:54
-
-
Save gekidoslair/9595ac7eae5a72a54152838b2801ea9e to your computer and use it in GitHub Desktop.
Simple class that allows you to spawn / instantiate any number of prefab game objects when a Unity scene loads. Useful for Bootstrap scenes & more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace PixelWizards.GameSystem.Controllers | |
{ | |
/// <summary> | |
/// Spawns any number of prefabs on Awake() when the scene loads | |
/// </summary> | |
public class SpawnOnAwake : MonoBehaviour | |
{ | |
public List<GameObject> spawners = new List<GameObject>(); | |
/// <summary> | |
/// Awake is the first thing called, spawn all of the items we need | |
/// </summary> | |
void Awake() | |
{ | |
foreach (var spawn in spawners) | |
{ | |
Instantiate(spawn, Vector3.zero, Quaternion.identity); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment