I want to add a lives system like candy crush in my game. I want to use an InvokeRepeating() function to add lives to an int called lives every second, but when the game is off it can’t add lives because the game object is destroyed.
Is there any way to make a script or game object active even when the game is off? If there is no way to do this, I might put something like this in feedback.
I have not made my script yet but this is what it my script might look like:
using UnityEngine;
using System.Collections;
public class LivesManager : MonoBehaviour {
void addLife () {
PlayerPrefs.SetInt("Lives", Playerprefs.GetInt("Lives") + 1);
}
void Start () {
PlayerPrefs.SetInt("Lives", 0);
InvokeRepeating("addLife", 1, 1);
}
}