// Returns the world position of start of the column (would be at y index -1) public Vector3 GetHoverPositionOfColumn(int index) { if (ConnectFour.IsColumnInRange(index)) { return(transform.TransformPoint(hoverBounds[index].center)); } return(Vector3.zero); }
// Returns true if we can drop a ball bool CanDrop() { return(isMyTurn && isHovering && ConnectFour.IsColumnInRange(hoverColumn) && !IsColumnFull(hoverColumn)); }
void Update() { // If this ball doesn't belong to us, ignore this. We only do Update for our ball if (!NetworkManager.IsMe(ownerPlayerId)) { return; } // Don't continue if it's not this players turn if (!isMyTurn) { return; } if (doHoverChecks) { // While the player has their main ball above the columns if (isHovering = ConnectFourBoard.Instance.WithinHoverBounds(transform.position)) { isHoveringLast = true; // Get the column index of the column nearest to the position (returns -1 if not near) hoverColumn = ConnectFourBoard.Instance.CheckHoverBounds(transform.position); // Check if the column is within range, and not occupied, show a visualBall above the column if (hoverColumn != hoverColumnLast && ConnectFour.IsColumnInRange(hoverColumn) && !IsColumnFull(hoverColumn)) { hoverColumnLast = hoverColumn; // Send CmdHoverAboveColumn to server, with the column index // This effectively "snaps" the visualBall to the column - disable this effect if we're an AI player if (!ConnectFourNPC.Instance.IsEnabled) { CmdHoverAboveColumn(NetworkManager.PlayerID, hoverColumn); } } // Drop with space if (Input.GetKeyDown(KeyCode.Space)) { Drop(); } } else if (isHoveringLast) { StopHovering(); } } // Manually move the player with left/right arrow if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow)) { if (Input.GetKeyDown(KeyCode.LeftArrow)) { debugColumn--; if (debugColumn < 0) { debugColumn = ConnectFour.BOARD_WIDTH - 1; } } else if (Input.GetKeyDown(KeyCode.RightArrow)) { debugColumn++; if (debugColumn >= ConnectFour.BOARD_WIDTH) { debugColumn = 0; } } transform.position = ConnectFourBoard.Instance.GetHoverPositionOfColumn(debugColumn); hoverColumn = hoverColumnLast = debugColumn; CmdHoverAboveColumn(ownerPlayerId, debugColumn); } }