Energy is not recharging (Simple Driving course)

When following simle driving coure evreything was going good and I even comleted the challange nathan gave on my own with minor mistake, But my energy doesnot seem to fill up, after that I followed nathan step by step and copied his code but it still seems my energy is not chaing from 0 to 5 after a minute

My code is attached along wth nathan, Not ure what I did wrong :slight_smile:

I changed the AddMinute to number to test it and my score script is score Handeler

Compared it with 2 diffrent text compration tool and couldt find anything

code is also attached here

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.SocialPlatforms.Impl;

public class MainManu : MonoBehaviour
{
    [SerializeField] private TMP_Text highscoreText;
    [SerializeField] private TMP_Text energyText;
    [SerializeField] private int maxEnergy;
    [SerializeField] private int energyRechargeDuration;

private int energy;

    private const string EnergyKey = "Energy";
    private const string EnergyReadyKey = "EnergyReady";

    private void Start()
    {
        int highScore = PlayerPrefs.GetInt(Scorehandeler.HighScoreKey, 0);

        highscoreText.text = $"High Score: {highScore}";

        energy = PlayerPrefs.GetInt(EnergyKey, maxEnergy);

        if (energy == 0)
        {
            string energyReadyString = PlayerPrefs.GetString(EnergyReadyKey, string.Empty);

            if (energyReadyString == string.Empty) { return; }

            DateTime energyReady = DateTime.Parse(energyReadyString);

            if (DateTime.Now > energyReady)
            {
                energy = maxEnergy;
                PlayerPrefs.SetInt(EnergyKey, energy);
            }
           
        }

        energyText.text = $"Play ({energy})";
    }

    public void Play()
    {
        if (energy < 1) { return; }
        {
            energy--;
            PlayerPrefs.SetInt(EnergyKey, energy);
            if (energy == 0)
            {
                DateTime energyReady = DateTime.Now.AddMinutes(1);
                PlayerPrefs.SetString(EnergyReadyKey, energyReady.ToString());

            }
            SceneManager.LoadScene("Scene_Game");
        }
    }
}

At this point, if you’re in the MainMenu, and the time has elapsed, we’re not really checking to see if the time has elapsed at a later point.

Nathan handles this in the lecture Energy Improvement.

Privacy & Terms