My problem is the value I get from Random.Range is not stored, but I get another value instead.
In level 1 I press the "claim" button to store a randomly-chosen score
In level 2 I retrieve the level 1 score using player preferences.
When I press the "claim" button again in level 2 I want to add the new random score to the score from level 1.
How can I do this?
Here is the code I'm using currently:
playermanager.cs
internal static int pointsAdd;
void Start()
{
PlayerManager.pointsAdd = PlayerPrefs.GetInt("score");
}
void FixedUpdate()
{
creditsText.text = PlayerPrefs.GetInt("score").ToString();
}
public void GetClaim()
{
PlayerManager.pointsAdd = PlayerPrefs.GetInt("score");
Debug.Log("pointadd" + PlayerManager.pointsAdd);
PlayerManager.pointsAdd = Random.Range(20, 40);
Debug.Log("Your Point is:" + PlayerManager.pointsAdd);
Debug.Log("random.range" + Random.Range(20, 40));
PlayerPrefs.SetInt("score", PlayerManager.pointsAdd);
creditsText.text = ("" + PlayerManager.pointsAdd);
}
Output: