- Home /
Hello I am trying to make idle game so what i am trying to do is each time a energy point is added I want my maxtime to go down by 1%. How would I go about doing that?
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);
}
}
Comment
Best Answer
Answer by Firestream1014 · Dec 13, 2020 at 12:03 AM
Everytime you receive and Energy point you want the Max Time to decrease?
void OnRecievePoints()
{
maxTime *= 0.99f;
}
which in your script, I think would fit right in... Well if the point you're referring to is that strength point, you can do this.
// Resets the time and adds to strength
if (currentTime == 0)
{
currentTime += maxTime;
playerInfo.strength += 1;
maxTime *= 0.99f;
}
else
{
}
maxTime needs to be rounded down, however, as it should be a whole number. Instead, try
maxTime = $$anonymous$$athf.FloorToInt(maxTime * 0.99f);
Your answer
Follow this Question
Related Questions
Go Idle after Animation 0 Answers
I can't look up and down because of animation on camera? 2 Answers
Character Looping Walk and Idle 1 Answer
match3 reorganize rematching 1 Answer