set level to be played only 3 times

How to set level to be played only 3 times. Player will only get to Play the level 3 times. Can anybody give some examples of code in C#

Hi aan_comel,

You just need static counter. In previous answer mistake is at line where we are setting player prefs on button click using counter it should be through fetching playerprefs but as you don’t need it so not correcting that.

public static int counter = 0;

void LoadLevel1()
{
if( counter<=3)
{
   counter++;
  
    Application.LoadLevel("levelName");

}
else
{
 print("level already loaded for three times");
}
}