Hello. If i hold button for not very long the power is set to 1. If i hold button long enough to get 5 power it resets to 0 as is in code. Why its not resetting to 0 every time I release button?
void Start()
{
secondsHeld = 0.0f;
buttonReleased = true;
}
void Update()
{
powerText.text = "Power: " + secondsHeld;
if (Input.GetKeyDown(KeyCode.Space))
{
buttonReleased = !buttonReleased;
StartCoroutine(HowLongButtonWasHeld());
}
if (Input.GetKeyUp(KeyCode.Space))
{
buttonReleased = !buttonReleased;
float forceToAdd = secondsHeld * ballSpeed;
SpawnBall(forceToAdd);
secondsHeld = 0.0f;
}
}
IEnumerator HowLongButtonWasHeld()
{
while (secondsHeld < 5 && !buttonReleased)
{
yield return new WaitForSeconds(0.4f);
secondsHeld++;
}