dimanche 2 mai 2021

How do I restrict one random prefab to be used only once but placed randomly with a whole bunch of prefabs of arrays on top of other object?

How do I restrict one random prefab to be used only once but placed randomly with a bunch of prefabs of arrays on top of other object?

using System.Collections.Generic;
using UnityEngine;

public class LevelRoomsScript : MonoBehaviour
{
    [SerializeField]
    private GameObject[] memberWoodArray = null;
    [SerializeField]
    private GameObject[] memberRoomPrefabArray = null;
    
    void Start()
    {
    
        foreach (GameObject localWood in memberWoodArray)
        {
            int localNumRoomPrefab = memberRoomPrefabArray.Length;
            int localRoomIndex = Random.Range(0, localNumRoomPrefab);
            
            GameObject localRoomPrefab = memberRoomPrefabArray[localRoomIndex];
            
            Instantiate(localRoomPrefab, localWood.transform.position, Quaternion.identity);
        }
    }
}



Aucun commentaire:

Enregistrer un commentaire