示例#1
0
    public void GenerateChunk(Vector3 position, Transform parent)
    {
        int prefabCount = _chunkPrefabs.Count;

        if (prefabCount < 1)
        {
            Debug.LogError("Chunk prefab list is empty!");
            return;
        }

        int selectedIndex  = Random.Range(0, prefabCount);
        var selectedPrefab = _chunkPrefabs[selectedIndex];

        Debug.Log($"New Road Chunk => Selected Chunk: {selectedPrefab.name}");

        // Spawn new
        GameObject chunkGO = GameObject.Instantiate(selectedPrefab, position, Quaternion.identity, parent);

        // Destroy first
        _chunkObjects.First.Value.Dispose();
        _chunkObjects.RemoveFirst();

        RoadChunkObject chunk = new RoadChunkObject(chunkGO);

        chunk.GenerateBuns(_bunGenerator);

        _chunkObjects.AddLast(chunk);
    }
示例#2
0
    public void GenerateChunk(Vector3 position, Transform parent)
    {
        GameObject roadChunk = GameObject.Instantiate(_initialChunkPrefab, position, Quaternion.identity, parent);

        RoadChunkObject chunk = new RoadChunkObject(roadChunk);

        chunk.GenerateBuns(_bunGenerator);

        _chunkObjects.AddLast(chunk);
    }