void Update() { int deltaColumn = 0, deltaRow = 0; if (Input.GetKeyDown(KeyCode.LeftArrow)) { deltaColumn = -1; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { deltaColumn = 1; } if (Input.GetKeyDown(KeyCode.UpArrow)) { deltaRow = 1; } else if (Input.GetKeyDown(KeyCode.DownArrow)) { deltaRow = -1; } // Since cursor is 2 blocks wide, constrain position from 0 to Board.Columns - 2 if (Column + deltaColumn >= 0 && Column + deltaColumn < BlockManager.Columns - 1) { Column += deltaColumn; } // Since cursor shouldn't access the invisible top row, constrain position from 0 to Board.Rows - 2 if (Row + deltaRow >= 0 && Row + deltaRow < BlockManager.Rows - 1) { Row += deltaRow; } if (Game.State == GameState.InMinigame) { if (Input.GetKeyDown(KeyCode.Space)) { if ((BlockManager.Blocks[Column, Row].State == BlockState.Idle || BlockManager.Blocks[Column, Row].State == BlockState.Empty) && (BlockManager.Blocks[Column + 1, Row].State == BlockState.Idle || BlockManager.Blocks[Column + 1, Row].State == BlockState.Empty) && (Row + 1 == BlockManager.Rows || Row + 1 < BlockManager.Rows && BlockManager.Blocks[Column, Row + 1].State != BlockState.Falling && BlockManager.Blocks[Column + 1, Row + 1].State != BlockState.Falling && BlockManager.Blocks[Column, Row + 1].State != BlockState.WaitingToFall && BlockManager.Blocks[Column + 1, Row + 1].State != BlockState.WaitingToFall)) { SetupSlide(BlockManager.Blocks[Column, Row], SlideDirection.Right); SetupSlide(BlockManager.Blocks[Column + 1, Row], SlideDirection.Left); BlockManager.Blocks[Column, Row].Slider.Slide(SlideDirection.Right); BlockManager.Blocks[Column + 1, Row].Slider.Slide(SlideDirection.Left); AudioSource.clip = SlideClip; AudioSource.pitch = 1f; AudioSource.Play(); } } if (Input.GetKeyDown(KeyCode.Return)) { Raiser.ForceRaise(); } } }
void Update() { if (GameManager.Instance.State == GameManager.GameState.MinigamePlay) { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null && hit.collider.name.Contains("Block")) { Block block = hit.collider.gameObject.GetComponent <Block>(); if (block.State == BlockState.Idle && block.Row >= 0 && block.Row < BlockManager.Rows - 1) { SelectedBlock = block; } } if (MinigameManager.Mode == BlockPartyModes.Survival) { if (Time.time - previousTapTime <= doubleTapDuration) { BoardRaiser.ForceRaise(); } previousTapTime = Time.time; } } if (Input.GetMouseButtonUp(0)) { SelectedBlock = null; } if (SelectedBlock != null) { float leftEdge = SelectedBlock.transform.parent.position.x + SelectedBlock.Column - SelectedBlock.transform.localScale.x / 2; float rightEdge = SelectedBlock.transform.parent.position.x + SelectedBlock.Column + SelectedBlock.transform.localScale.x / 2; Block leftBlock = null, rightBlock = null; Vector3 mousePosition = Input.mousePosition; if (Camera.ScreenToWorldPoint(mousePosition).x < leftEdge && SelectedBlock.State == BlockState.Idle && SelectedBlock.Column - 1 >= 0 && (BlockManager.Blocks[SelectedBlock.Column - 1, SelectedBlock.Row].State == BlockState.Idle || BlockManager.Blocks[SelectedBlock.Column - 1, SelectedBlock.Row].State == BlockState.Empty) && (SelectedBlock.Row + 1 == BlockManager.Rows || (SelectedBlock.Row + 1 < BlockManager.Rows && BlockManager.Blocks[SelectedBlock.Column - 1, SelectedBlock.Row + 1].State != BlockState.Falling && BlockManager.Blocks[SelectedBlock.Column - 1, SelectedBlock.Row + 1].State != BlockState.WaitingToFall))) { leftBlock = BlockManager.Blocks[SelectedBlock.Column - 1, SelectedBlock.Row]; rightBlock = SelectedBlock; SelectedBlock = leftBlock; } if (Camera.ScreenToWorldPoint(mousePosition).x > rightEdge && SelectedBlock.State == BlockState.Idle && SelectedBlock.Column + 1 < BlockManager.Columns && (BlockManager.Blocks[SelectedBlock.Column + 1, SelectedBlock.Row].State == BlockState.Idle || BlockManager.Blocks[SelectedBlock.Column + 1, SelectedBlock.Row].State == BlockState.Empty) && (SelectedBlock.Row + 1 == BlockManager.Rows || (SelectedBlock.Row + 1 < BlockManager.Rows && BlockManager.Blocks[SelectedBlock.Column + 1, SelectedBlock.Row + 1].State != BlockState.Falling && BlockManager.Blocks[SelectedBlock.Column + 1, SelectedBlock.Row + 1].State != BlockState.WaitingToFall))) { leftBlock = SelectedBlock; rightBlock = BlockManager.Blocks[SelectedBlock.Column + 1, SelectedBlock.Row]; SelectedBlock = rightBlock; } if (leftBlock != null && rightBlock != null) { SetupSlide(leftBlock, SlideDirection.Right); SetupSlide(rightBlock, SlideDirection.Left); leftBlock.Slider.Slide(SlideDirection.Right); rightBlock.Slider.Slide(SlideDirection.Left); AudioSource.clip = SlideClip; AudioSource.Play(); } } } }