Example #1
0
    private void Awake()
    {
        _usedRooms = new List <GameObject>();

        GameObject newRoom;

        _startPosition.z = -_distanceBetweenRooms * _numberOfRoomsToStart;
        Vector3 newPosition = _startPosition;

        List <int> roomIndexes = SomeMath.CreateRandomUniqueIndexes(_numberOfRooms - _numberOfDuplicatedRooms, 0, _rooms.Length);

        for (int i = 0; i < _numberOfRooms - _numberOfDuplicatedRooms; i++)
        {
            newRoom = Instantiate(_rooms[roomIndexes[i]]);
            _usedRooms.Add(newRoom);
        }
        for (int i = 0; i < _numberOfDuplicatedRooms; i++)
        {
            newRoom = Instantiate(_usedRooms[i + _numberOfRoomsToStart]);
            _usedRooms.Add(newRoom);
        }

        for (int i = 0; i < _usedRooms.Count; i++)
        {
            newPosition.z = i * _distanceBetweenRooms;
            _usedRooms[i].transform.position = _startPosition + newPosition;
            _usedRooms[i].transform.parent   = gameObject.transform;

            _usedRooms[i].AddComponent <Room>();
            _usedRooms[i].GetComponent <Room>().RoomNumber = i;
        }

        if (_teleport != null)
        {
            newPosition   = _teleport.transform.position;
            newPosition.z = _usedRooms[_numberOfRooms - _numberOfDuplicatedRooms].transform.position.z + 0.5f;
            _teleport.transform.position = newPosition;
        }

        //ObjectPool
        for (int i = 0; i < _usedRooms.Count; i++)
        {
            _usedRooms[i].SetActive(false);
        }

        for (int i = 0; i < _numberOfRoomsVisibleToPlayer; i++)
        {
            _usedRooms[i].SetActive(true);
        }
    }
Example #2
0
    private void Start()
    {
        _indexes  = new List <int>();
        _bonfires = new List <GameObject>();
        _indexes  = SomeMath.CreateRandomUniqueIndexes(_numberOfBonfires, 0, _transforms.Length);

        for (int i = 0; i < _numberOfBonfires; i++)
        {
            GameObject newBonfire = Instantiate(_bonfirePrefab);
            newBonfire.transform.position = _transforms[_indexes[i]].position;
            newBonfire.transform.parent   = _parent.transform;

            _bonfires.Add(newBonfire);
        }
    }