Saving how many times the game was restarted

Hi All!

I’m trying to implement an ad, but I only want to show the add after the user clicked on “Try Again” 5 times.

I’m having problems saving my retryCount.

Thanks in advance:

public GameObject playerC;
public GameObject[ ] obstacle;
public GameObject gameOverPanel;

public int retryCount;

public float obstacleDistance;

public int spawnRate;
public int spawnTime;

public Text fallDistance;
public Text finalScore;

void Start()
{
Physics.gravity = new Vector3(0, -558, 0);
playerC.transform.position = new Vector3(0, 1000, -10);
InvokeRepeating(“spawnObstacle”, spawnTime, spawnRate);
gameOverPanel.gameObject.SetActive(false);

PlayerPrefs.GetInt(“retry”, retryCount);
Debug.Log(retryCount);
}

public void Update()
{

}

void spawnObstacle()
{

}
public void RestartGame()
{
retryCount++;
PlayerPrefs.SetInt(“retry”, retryCount);
UnityEngine.SceneManagement.SceneManager.LoadScene(“Game”);
}

PlayerPrefs.Save();

It’s worth noting that the format is:

int PlayerPrefs.GetInt(string key, default value)  // you don't want to put your variable in the default value.
// used like..
retryCount = PlayerPrefs.GetInt("retry", 0);   // meaning, assign the return value of key "retry" to the 'retryCount' variable, unless it's not found, then assign zero (0).

Using: PlayerPrefs.GetInt(“retry”); does nothing, as it’s never assigned**

Man! You’ve solved my problem once again! Thank you!!!

:slight_smile: hey np, you’re welcome.

I’m on the last part of completing my game. Thanks again man!