Advertisement
johnnygoodguy2000

Collectable_Spawner.cs

Dec 25th, 2024 (edited)
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Collectable_Spawner : MonoBehaviour
  6. {
  7.     [SerializeField]
  8.     private List<GameObject> _collectablePrefabs;
  9.  
  10.     public void SpawnCollectable(Vector2 position)
  11.     {
  12.         int index = Random.Range(0, _collectablePrefabs.Count);
  13.         var selectedCollectable = _collectablePrefabs[index];
  14.  
  15.         Instantiate(selectedCollectable, position, Quaternion.identity);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement