Object spawn at spawn points

Hello!

I want to make a spawn points on or in the furnitures(desk,chair,closet,etc) and make the objects spawn randomly.

There will be like 9 spawn points.

The objects don’t need a random Z( if Z is random, then the objects are gonna float from the furnitures).

Help me plz!

  1. Create a new Empty gameobject,

  2. Create a new script called Spawner and copy-paste the following code

  3. In your scene, create new empties and drag & drop them in the spawnPoints array in the inspector of the Spawner component

  4. Get a reference to the Spawner script (using public attribute to your own class, or by using FindObjectOfType<Spawner>() and call the PlaceTransform function

    using UnityEngine;
    using System.Collections;

    public class Spawner : MonoBehaviour
    {
    [SerializeField]
    private System.Collections.Generic.List spawnPoints;

    private System.Collections.Generic.List<Transform> availableSpawnPoints;
    
    private void Awake()
    {
        availableSpawnPoints = new System.Collections.Generic.List<Transform>(spawnPoints);
    }
    
    public void PlaceTransform( Transform transformToPlace )
    {
        if (availableSpawnPoints.Count > 0)
        {
            int index = Random.Range(0, availableSpawnPoints.Count);
            transformToPlace.position = availableSpawnPoints[index].position;
            availableSpawnPoints.RemoveAt(index);
        }
        else
        {
            Debug.LogError("No spawn point available");
        }
    }
    

    }