using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pushupWait : MonoBehaviour
{
public int maxTime = 100;
public int currentTime;
public int Tick = 1;
public PlayerInfo playerInfo;
public pushupButtons PushupButtons;
public timerBarScript timeBar;
private bool coroutineRunning = false;
//Makes a time countdown
public IEnumerator PushupTime()
{
coroutineRunning = true;
while (PushupButtons.pushupValue > 0)
{
yield return new WaitForSeconds(Tick);
TimeisTicking(1);
}
coroutineRunning = false;
}
// Start is called before the first frame update
void Start()
{
currentTime = maxTime;
timeBar.SetMaxTime(maxTime);
}
// Update is called once per frame
void Update()
{
// Checks if player had add energy to do the action and starts the timer
if ((PushupButtons.pushupValue > 0 ) && !coroutineRunning)
{
StartCoroutine(PushupTime());
}
else
{
}
// Resets the time and adds to strength
if (currentTime == 0)
{
currentTime += maxTime;
playerInfo.strength += 1;
}
else
{
}
}
// Substracts time when called
void TimeisTicking(int oneTick)
{
currentTime -= oneTick;
timeBar.SetTime(currentTime);
}
}