IEnumerator FindNextBlockPosCourouinte(int lastDir, bool bothDirChecked = false) { Collider[] hitColliders = Physics.OverlapSphere(_centerPos, _overlapSphereRadius); BlockScript adjacentBlock = null; int i = 0; //check the adjacent block. // if a block is available in the same direction then move in the same direction //else check opposite direction and move while (i < hitColliders.Length) { if (hitColliders[i].transform.parent == null || hitColliders[i].transform.parent == transform) { i++; continue; } //checking if the movement directio is left or right Vector3 dir = hitColliders[i].transform.parent.position - transform.position; Vector3 perp = Vector3.Cross(dir.normalized, transform.forward); float dot = Vector3.Dot(perp, transform.up); bool directionCheck = Mathf.Sign(lastDir) == 1 ? dot <= -0.95f : dot >= 0.95f; if (directionCheck) { adjacentBlock = hitColliders[i].transform.parent.GetComponent <BlockScript>(); break; } i++; } if (adjacentBlock == null) { if (!bothDirChecked) { StartCoroutine(FindNextBlockPosCourouinte(lastDir * -1, true)); } yield break; } //TODO : put the delay in scriptable object yield return(new WaitForSeconds(0.5f)); adjacentBlock.SetSpecialBlock(BlockType.Gem, lastDir); SetBlockType(BlockType.normal); }
public void StartGemBlockSequence() { BlockScript block = null; int i = _tower.Count - 1; while (i >= _lowestActiveLevel) { //check if this level has all blocks left if (_tower[i].Count == _gameLevel.TowerSetting.BlockCount) { int randomIndex = UnityEngine.Random.Range(0, _tower[i].Count); block = _tower[i][randomIndex]; block.SetSpecialBlock(BlockType.Gem, 1); break; } i--; } }