using UnityEngine; public sealed class PrefabSpawner : MonoBehaviour { [SerializeField] private GameObject prefab; private int nextId = 1; [ContextMenu("Spawn One")] public void SpawnOne() { if (!Application.isPlaying) { Debug.LogWarning("Enter Play mode first.", this); return; } if (prefab == null) { Debug.LogError("Assign a prefab asset.", this); return; } GameObject instance = Instantiate(prefab, transform.position, transform.rotation); instance.name = "Spawned-" + nextId++; Debug.Log(instance.name, instance); Destroy(instance, 2f); } }