EDIT i got the life going down mechanics, i just need the time script. Everytime deaths go to 5 in a level i want to lower the PlayerPrefs for the Big Lives(ones in the menu, that decide wether you can play or not) by one. I dont know how to just decrease it instead of setting the PlayerPrefs to a specific number. Also if Big Lives <= 5 i want a timer to start that of reaches 10 min it would replenish one Big Life. But i cant really find anything. Can anybody help?
If you just want to decrease the number by one you could do: bigLives--;
or if you want to decrease by a certain number then you do this: bigLives-= 2;
which subtracts two from the value.
For the timer I usually make something like this with the startLifeTimer being the amount between each live. Then subracting one second from lifeTimer until it equals 0, where we add a life and reset the timer.
float startLifeTimer;
float lifeTimer;
void Start
{
lifeTimer = startLifeTimer;
}
if(bigLives <= 5)
if(lifeTimer < 0)
{
bigLives++;
PlayerPrefs.SetFloat("BigLives", bigLives);
lifeTimer = startLifeTimer;
}
else
{
lifeTimer -= Time.deltaTime;
}
use coroutines, so something like this:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Start()
{
StartCoroutine(ResetLives);
}
private IEnumerator ResetLives()
{
while(true)
{
yield return new WaitForSeconds(10f);
player.lives=10;
}
}
}
More info on coroutines:
https://stackoverflow.com/questions/53139259/making-a-timer-in-unity