Hi, I’ve recently been watching tutorials on the process of making a idle/incremental game. Now I understand they are very overused and common now-a-days on unity. I’ve gotten done with a lot of the process, but I’m still kind of stuck on the cash/money per sec. Could someone help me out please?
It’s probably just me, but could you please elaborate a bit more on this? What exactly are you trying to do?
No, I understand completely. I want to be able to ‘purchase’ a upgrade that gives me a certain amount of cash per sec. For instance if I bought a upgrade that cost ___ cash and would give me ___ cash per ___ seconds. Sorry if I don’t make it sound clear, I’m kind of new to all of this.
So you want like:
- Player spends/invests $100
- Player earns a total of $120 over the next 120 seconds
Is that what you mean?
Relevant: does your currency system support fractions or is it just whole dollars?
You just need to watch the Time.time, and when it’s time to pay out more cash, do it. Something like this.
public class CashPerSec : MonoBehaviour {
public float payout = 1;
public float interval = 1;
float nextPayoutTime;
void Update() {
if (Time.time > nextPayoutTime) {
Debug.Log("Awarding $" + payout + "!");
GetComponent<Wallet>().AddCash(payout);
nextPayoutTime = Time.time + interval;
}
}
}
Note that I wasn’t sure how you’re keeping track of your cash, so I just imagined you have some “Wallet” component on the same object, that has a public AddCash method.
Yes this helped, but one other thing. Could you help me with the public integers? I’m looking to make multiple upgrades, so I could edit them individually.