void PickClub() { distance = Vector3.Distance(GameManager.instance.ballScript.gameObject.transform.position, GameManager.instance.ballScript.hole.transform.position); BoardCreator.TileType onTileType = GameManager.instance.ballScript.onTileType; // pick the speed of the bar first switch (onTileType) { case (BoardCreator.TileType.sand): powerGainSpeed = firstPowerGainSpeed * 2; accuracyGainSpeed = firstAccuracyGainSpeed * 2; break; case (BoardCreator.TileType.fairway): powerGainSpeed = firstPowerGainSpeed; accuracyGainSpeed = firstAccuracyGainSpeed; break; case (BoardCreator.TileType.rough): powerGainSpeed = firstPowerGainSpeed * 1.5f; accuracyGainSpeed = firstAccuracyGainSpeed * 1.5f; break; } // then choose the correct club (maximum value of the power bar) if (distance >= 4) { switch (onTileType) { case (BoardCreator.TileType.sand): powerSlider.maxValue = clubs["Sand"]; powerGhostSlider.maxValue = clubs["Sand"]; flagSlider.maxValue = clubs["Sand"]; break; case (BoardCreator.TileType.fairway): powerSlider.maxValue = clubs["Normal"]; powerGhostSlider.maxValue = clubs["Normal"]; flagSlider.maxValue = clubs["Normal"]; break; case (BoardCreator.TileType.rough): powerSlider.maxValue = clubs["Normal"]; powerGhostSlider.maxValue = clubs["Normal"]; flagSlider.maxValue = clubs["Normal"]; break; } } else { powerSlider.maxValue = clubs["Putter"]; powerGhostSlider.maxValue = clubs["Putter"]; flagSlider.maxValue = clubs["Putter"]; } }
void FixedUpdate() { if (!isColliding) { onTileType = GameManager.instance.boardCreator.GetTileTypeFromPosition(transform.position); } SetFriction(); if (!inHole && (rbody.velocity.x >= -0.05 && rbody.velocity.x <= 0.05 && rbody.velocity.y >= -0.05 && rbody.velocity.y <= 0.05) && !GameManager.instance.inputManager.inputActive) { GameManager.instance.inputManager.StartPower(); } isMoving = (Mathf.Abs(rbody.velocity.x) >= 0.05 || Mathf.Abs(rbody.velocity.y) >= 0.05); if (!isMoving) { DrawLineToHole(); line.enabled = true; if (!checkedForTrees) { CheckForTrees(); } } else { line.enabled = false; } if (isAirborne) { velocity += spriteGravity * 3 * Time.deltaTime; height += velocity * 3 * Time.deltaTime; sprite.localPosition = new Vector3(0, height, 0); sprite.localScale = new Vector3(height + 1, height + 1, 1); } if (height <= Mathf.Epsilon) { isAirborne = false; sprite.localPosition = Vector2.zero; if (onTileType == BoardCreator.TileType.outOfBounds || onTileType == BoardCreator.TileType.water) { rbody.velocity = Vector2.zero; transform.position = previousPosition; height = 0; velocity = 0; isAirborne = false; Physics2D.gravity = Vector3.zero; } if (!bounced) { Bounce(); } } if (!isAirborne && Mathf.Abs(rbody.velocity.x) < 2f && Mathf.Abs(rbody.velocity.y) < 2f && Vector2.Distance(hole.transform.position, transform.position) < 0.1f) { BallInTheHole(); } }