void ActivateBlock() { if (InactivePool.Count > 0) { BlockController NewBlock = InactivePool[0]; InactivePool.RemoveAt(0); ActivePool.Add(NewBlock); NewBlock.Activate(new Vector3(-25, .5f, Mathf.RoundToInt(Random.Range(-5, 6))), Random.Range(0.9f, BlockSize), this); } else { GameObject newBlock = Instantiate(BlockPrefab, new Vector3(0, 0, 0), Quaternion.identity); ActivePool.Add(newBlock.GetComponent <BlockController>()); newBlock.GetComponent <BlockController>().Activate(new Vector3(-25, .5f, Mathf.RoundToInt(Random.Range(-5, 6))), Random.Range(0.9f, BlockSize), this); } }
public void CallNext() { if (GameManager.IsPaused || GameManager.IsRoundOver && player != GameManager.PlayerIndex.Noll) { Debug.Log("Paused"); return; } if (_nextBlocks.Count <= 0) { _nextBlocks = new Queue <GameObject>(blockList.OrderBy(x => Random.value)); } if (_currentBlock) { for (int i = 0; i < _currentBlock.transform.childCount; i++) { _currentBlock.transform.GetChild(i).gameObject.layer = _inactiveBlockLayer; foreach (Collider childCollider in _currentBlock.transform.GetChild(i).GetComponentsInChildren <Collider>()) { childCollider.gameObject.layer = _inactiveBlockLayer; } } } Vector3 spawnPos = gameObject.transform.position; spawnPos.x += Random.Range(BlockSpawnWidth * -0.5f, BlockSpawnWidth * 0.5f); GameObject cached = Instantiate(_nextBlocks.Dequeue(), spawnPos, Quaternion.identity); BlockController block = cached.GetComponent <BlockController>(); block.Activate(this, player); for (int i = 0; i < block.transform.childCount; i++) { block.transform.GetChild(i).gameObject.layer = _activeBlockLayer; foreach (Collider childCollider in block.transform.GetChild(i).GetComponentsInChildren <Collider>()) { childCollider.gameObject.layer = _activeBlockLayer; } } _currentBlock = block; if (OnSpawner != null) { OnSpawner.Invoke(block, player); } //Setting new block if (_nextBlocks.Count < 1) { _nextBlocks = new Queue <GameObject>(blockList.OrderBy(x => Random.value)); } OnNextBlockShow?.Invoke(_nextBlocks.Peek()); }