hello sir , i am new to unity and i have learned C# language actually i am making a game like flappy bird in which i have a shop menu i want to save coins in shop menu and i know for that i have to use playerprefsget int and setint . i am able to save the coins but after i play the level it save that coin in shop menu .
i mean to say its not incrementing like if i have 15 saved coins and if i play back and collect 16 coins
i get 16 coins only in my shop menu instead of 31…thats the makor problem i am facing .
please help me with my this problem . although my code is:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class purchase : MonoBehaviour
{
// private int currentvalue;
private int gettingvalue;
[SerializeField]
private Text cointext;
int totalvalue;
int currentvalue ;
private void Awake()
{
addcoins();
}
private void Update()
{
//
}
public void addcoins()
{
gettingvalue = treetry.instance.finalscore;
currentvalue += currentvalue + gettingvalue;
totalvalue += currentvalue + totalvalue;
cointext.text = totalvalue.ToString();
PlayerPrefs.SetInt("totalcoins", totalvalue);
PlayerPrefs.GetInt("totalcoins", totalvalue);
PlayerPrefs.Save();
}
}
this code i have wriiten myself .
please help me your help is appreciated…
thank you in advance.