Skip to content

Instantly share code, notes, and snippets.

@gekidoslair
Created December 16, 2022 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gekidoslair/9595ac7eae5a72a54152838b2801ea9e to your computer and use it in GitHub Desktop.
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
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