2 added 533 characters in body
source | link

PlayerPrefs.SetInt(name_key, value); saves your value with the name key specified in a string.

value = PlayerPrefs.GetInt(name_key); gets the value which was previously saved with SetInt function, and sets it back to value.

So when you want to save your score you have to do this:

PlayerPrefs.SetInt("score", pointAdd);

But then for loading it into the second level, you have to do this:

pointAdd = PlayerPrefs.GetInt("score");

And finally, if you want to check if there is a score saved in your PlayerPrefs, you have to do this:

PlayerPrefs.HasKey("Score");

Which returns a boolean.

For more information:

list of PlayerPrefs functions: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Set Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html

Get Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.GetInt.html

Has Key: https://docs.unity3d.com/ScriptReference/PlayerPrefs.HasKey.html

Edit

I didn't quite catch what you were trying to achieve, but you can have these functions to help you:

void SaveScore(int score){
    PlayerPrefs.SetInt("score", score);
}
int LoadScore(int defaultValue = 20){
    return PlayerPrefs.GetInt("score", defaultValue);
}

The LoadScore function is equivalent to this:

int LoadScore(int defaultValue = 20){
    if(PlayerPrefs.HasKey("score"))
        return PlayerPrefs.GetInt("score");
    return defaultValue;
}

PlayerPrefs.SetInt(name_key, value); saves your value with the name key specified in a string.

value = PlayerPrefs.GetInt(name_key); gets the value which was previously saved with SetInt function, and sets it back to value.

So when you want to save your score you have to do this:

PlayerPrefs.SetInt("score", pointAdd);

But then for loading it into the second level, you have to do this:

pointAdd = PlayerPrefs.GetInt("score");

And finally, if you want to check if there is a score saved in your PlayerPrefs, you have to do this:

PlayerPrefs.HasKey("Score");

Which returns a boolean.

For more information:

list of PlayerPrefs functions: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Set Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html

Get Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.GetInt.html

Has Key: https://docs.unity3d.com/ScriptReference/PlayerPrefs.HasKey.html

PlayerPrefs.SetInt(name_key, value); saves your value with the name key specified in a string.

value = PlayerPrefs.GetInt(name_key); gets the value which was previously saved with SetInt function, and sets it back to value.

So when you want to save your score you have to do this:

PlayerPrefs.SetInt("score", pointAdd);

But then for loading it into the second level, you have to do this:

pointAdd = PlayerPrefs.GetInt("score");

And finally, if you want to check if there is a score saved in your PlayerPrefs, you have to do this:

PlayerPrefs.HasKey("Score");

Which returns a boolean.

For more information:

list of PlayerPrefs functions: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Set Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html

Get Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.GetInt.html

Has Key: https://docs.unity3d.com/ScriptReference/PlayerPrefs.HasKey.html

Edit

I didn't quite catch what you were trying to achieve, but you can have these functions to help you:

void SaveScore(int score){
    PlayerPrefs.SetInt("score", score);
}
int LoadScore(int defaultValue = 20){
    return PlayerPrefs.GetInt("score", defaultValue);
}

The LoadScore function is equivalent to this:

int LoadScore(int defaultValue = 20){
    if(PlayerPrefs.HasKey("score"))
        return PlayerPrefs.GetInt("score");
    return defaultValue;
}
1
source | link

PlayerPrefs.SetInt(name_key, value); saves your value with the name key specified in a string.

value = PlayerPrefs.GetInt(name_key); gets the value which was previously saved with SetInt function, and sets it back to value.

So when you want to save your score you have to do this:

PlayerPrefs.SetInt("score", pointAdd);

But then for loading it into the second level, you have to do this:

pointAdd = PlayerPrefs.GetInt("score");

And finally, if you want to check if there is a score saved in your PlayerPrefs, you have to do this:

PlayerPrefs.HasKey("Score");

Which returns a boolean.

For more information:

list of PlayerPrefs functions: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Set Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html

Get Int : https://docs.unity3d.com/ScriptReference/PlayerPrefs.GetInt.html

Has Key: https://docs.unity3d.com/ScriptReference/PlayerPrefs.HasKey.html