Hello, I would like to add a function to my game, so if the player holds a left mouse button for too long (let’s assume for 5 seconds) the ball is fired anyway. I’ve added float timer, and float hold duration but I must have done something wrong because my game is working, but it is not counting time, so it makes it too easy to play. I’ve tried solution from this topic link text but it didn’t work. Code:
if (Input.GetButtonDown("Fire1"))//mouse button was clicked
{
if (hit.collider != null)
{
if (hit.collider.transform.root.name == name)
{
trajectoryVisible = true;
}
}
}
//the mouse button was released or trajectory path touched screen edge
if ((Input.GetButtonUp("Fire1") || (paraboleReachedEndOfScreen && Input.GetButton("Fire1"))) && !isClicked && trajectoryVisible)
{
trajectoryVisible = false;
isClicked = true;
GameStatus.ball.ballRB.constraints = RigidbodyConstraints2D.FreezeRotation;
ballRB.velocity = shotForce;
foreach (var dot in dots)
dot.transform.position = Vector3.zero;
}