Need ask expericene/idea how to make stamina/engry resume in offline mode

Sorry my bad english, I don’t know how to say this. Example with this

After reduct any point, it’ll need time for gain 1 point (example 10 minutes for a point). Player can wait ingame or outgame. Point will gain 1 after done time reduct to zero (catch at time it reduct), if point still not full then point will auto make calculate time and do again
I think need use PlayerPrefs for save/load data, but I don’t know how about its formula and a good way to do

Just to clarify, you want 10 mins to pass… after which you gain a point?

Of course you can save the time to player prefs or some other format. This could be ‘hacked’ by changing the system time, and you could use an internet time server to fix that (for offline)… or just ignore that, if you don’t care.

If I got that much correct, you could set “Next Point = current time + 10 mins”. You can also work out as many other points you might want by Next Point + (another) 10 mins, and so on.

Yes you take correct what I mean. Temp pass how about time hack. I’m wondering how about “Next Point = current time + 10 mins”. Example the time is 06:00:00, bonus 10 minutes then it’s 06:10:00, then?
Sorry I’m too newbie. I wish have a simple example for easy understand how can make this work

Maybe you can search for comparing DateTime or something like that.
You could run this “timer” in-game, or just calculate the amount of time passed when the user first starts up (and figure out if they’ve earned any points then and if so, how many).

Thank you :slight_smile:

Sure, np. Feel free to write back your progress later after you look into it :slight_smile:

nearly complete, still have little incorrect. I don’t know why when I try start in few times, the cooldown timeleft is show incorrect. Here’s my example:
EDIT: fixed my problem
EDIT2: found other problem, fixed. But still not perfect correct (incorrect 1-2 seconds)

action for lost life:

public class DoSomething : MonoBehaviour
    {
        public LifesResumeControl life;
   
        public void PerformTransition()
        {
            if (life != null)
            {
                if (life.currentLife > 0)
                {
                    life.currentLife -= 1;
                    if (life._timer <= 0)
                    {
                        life.DoTimer();
                    }
                    PlayerPrefs.SetInt("CurrentLife", life.currentLife);
                    PlayerPrefs.SetString("TimeUsedLife", DateTime.Now.ToString());               
                   // DoSomething
                }
            }
        }
    }

life resume control

public class LifesResumeControl : MonoBehaviour
{

    public GameObject targetLife;
    public GameObject targetTimer;
    public int maxLife = 9;
    public int currentLife, tempResult;
    public int secondsFor1Life = 120;
    public float _timer = 0f;
    float convertTimer;
    string getUsedLifeTimer;
    DateTime convertTime, theTime;

    void Start()
    {       
        currentLife = PlayerPrefs.GetInt("CurrentLife", maxLife);
        getUsedLifeTimer = PlayerPrefs.GetString("TimeUsedLife", "");
        if (getUsedLifeTimer != "")
        {
            if (currentLife >= maxLife)
            {
                PlayerPrefs.SetString("TimeUsedLife", "");
            }
            else
            {
                DateTime.TryParse(getUsedLifeTimer, out convertTime);
                if (convertTime != null)
                {
                    TimeSpan span = System.DateTime.Now - convertTime;
                    double seconds = span.TotalSeconds;
                    tempResult = (int)seconds / secondsFor1Life;
                    if (tempResult >= 1)
                    {
                        currentLife  += tempResult;                   
                        PlayerPrefs.SetInt("CurrentLife", currentLife);
                        if (currentLife >= maxLife)
                        {
                            currentLife = maxLife;
                            _timer = 0;
                            PlayerPrefs.SetString("TimeUsedLife", "");
                        }
                        else
                        {
                            _timer = ((float)secondsFor1Life) - ((float)seconds % secondsFor1Life);
                            theTime = convertTime.AddSeconds(seconds);
                            PlayerPrefs.SetString("TimeUsedLife", theTime.ToString());
                        }

                    }
                    else
                    {
                        _timer = ((float)secondsFor1Life) - ((float)seconds % secondsFor1Life);
                    }
                }
            }
        }       
        //StartCoroutine("getTime");
    }

    void Update()
    {
        string minutes = Mathf.Floor(_timer / 60).ToString("00");
        string seconds = Mathf.RoundToInt(_timer % 60).ToString("00");

        targetLife.GetComponent<Text>().text = currentLife.ToString();
        targetTimer.GetComponent<Text>().text = minutes + ":" + seconds;
        if (currentLife < maxLife)
        {
            _timer -= Time.deltaTime;
            if (_timer <= 0)
            {
                currentLife++;
                PlayerPrefs.SetInt("CurrentLife", currentLife);
                PlayerPrefs.SetString("TimeUsedLife", DateTime.Now.ToString());
                if (currentLife < maxLife)
                {
                    DoTimer();
                }
                else
                {
                    _timer = 0;
                    PlayerPrefs.SetString("TimeUsedLife", "");
                }
            }
        }
        if (currentLife < 0)
        {
            currentLife = 0;
            _timer = 0;
        }
        if (currentLife > maxLife)
        {
            currentLife = maxLife;
            _timer = 0;           
        }
    }
    
    public void DoTimer()
    {       
        convertTimer = (float)secondsFor1Life;
        _timer = convertTimer;
    }

    IEnumerator getTime()
    {
        WWW www = new WWW("http://www.saadkhawaja.com/gettime.php");
        yield return www;
        Debug.Log("Time on the server is now: " + www.text);
    }
}

And I’m trying get internet time for avoid time cheat. Do you know any host can get time same format with this system datetime?

I didn’t read your code too closely, but did you work out your issues?

If you only need to show integers, you could update your text less often for the time in Update. For sure, you can update the text for lives less often (as in only when you gain/lose one).

The question about internet time : I’ve never actually used an internet time server, however… the format in which it comes shouldn’t matter too much, so long as you can convert it to something useful :slight_smile:

Ya, it’s work but not perfect, still have little incorrect, maybe by my formulas. I’m a newbie, still missing alot experiences, many things I want but don’t know how to do…

Sure, well it takes time and practice :slight_smile:

You can put some Debug.Log statements in your code to see where it’s going wrong, maybe that will help.