39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System;
|
|
using Unity.Profiling;
|
|
using UnityEngine;
|
|
|
|
namespace DefaultNamespace
|
|
{
|
|
public class MassInstantiation : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject prefab;
|
|
[SerializeField] private int objectsToSpawn = 1000;
|
|
[SerializeField] private bool isInstantiating;
|
|
|
|
private static readonly ProfilerMarker _profilerMarker = new ProfilerMarker("MassInstantiationMarker");
|
|
|
|
private void Update()
|
|
{
|
|
if (isInstantiating) InstantiateObjects();
|
|
if (Input.GetKeyDown(KeyCode.Space)) DestroyAllChildren();
|
|
}
|
|
|
|
public void InstantiateObjects()
|
|
{
|
|
_profilerMarker.Begin();
|
|
for (int i = 0; i < objectsToSpawn; i++)
|
|
{
|
|
Instantiate(prefab, transform);
|
|
}
|
|
_profilerMarker.End();
|
|
}
|
|
|
|
private void DestroyAllChildren()
|
|
{
|
|
for (int i = transform.childCount - 1; i >= 0; i--)
|
|
{
|
|
Destroy(transform.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
}
|
|
} |