I have to load a level after it reaches a score.

I have a player Pref that i want to load a new level only if the score is 3. Can anyone help me?

function OnTriggerEnter (other : Collider) {
if (PlayerPrefs == 3){
       yield WaitForSeconds (3);
       if( Application.loadedLevel + 1 < Application.levelCount )
       Application.LoadLevel( Application.loadedLevel + 1 );
        
   else { 
     Application.LoadLevel (0);
   }
}

1 Answer

1

You need to provide a key to query.

if (PlayerPrefs.GetInt("someValue") >= 3)
{
    // do stuffs
}

Is this what you mean? function OnTriggerEnter (other : Collider) { if (PlayerPrefs.GetInt("3") >= 3) { yield WaitForSeconds (3); if( Application.loadedLevel + 1 < Application.levelCount ) Application.LoadLevel( Application.loadedLevel + 1 ); else Application.LoadLevel (0); } }