I Have A Question Which is A Liitle Tricky I Suppose

So In My Temple Run Game I Have Accomplished a lot (Though Making It For Pc) I Am Stucked on Diamonds Or COins .
My Question is that My DIamonds Get Saved Using PlayerPrefs But evry time one plays it removes the other diamonds which were saved previously But i want them to be added and not removed

If You Didn’t understand what i am trying to say
You May Have Played Temple Run Or SubWay Surfers
When U Play It For The First Time Suppose You Get 100 coins in first But When You Play Again suppose you get 50 coins in The Game They Get Added And You Get Your coins to be 150

``````#pragma strict
static var Diamond :int = 0 ;
var Text = "Diamonds  :  " + 0 ;
var NumDiamonds : int = 1;
static var  Total :int;
function Awake(){

}
function Start () {

}

function Update () {

if(P_C.DiamondMultiplier){
if(Shop.Boost1){

NumDiamonds = 2;
}
if(Shop.Boost2){
NumDiamonds = 3;
}
if(Shop.Boost3){
NumDiamonds = 4;
}
}
PlayerPrefs.SetInt("Diamonds",Diamonds.Diamond);
PlayerPrefs.SetInt("Diamonds" , PlayerPrefs.GetInt("Diamonds")+Diamond);
}
}
function OnTriggerEnter(other:Collider){

if (other.tag == "Diamonds") {
Debug.Log("Other object is a Coins");
Diamond +=  NumDiamonds;  // They Are A Variable Used For Multiplying Boosts
Text = "Diamonds  :  " + Diamond;
Debug.Log("Score is now " + Diamond);
Destroy(other.gameObject);

}

if(P_C.DiamondMultiplier){

}
}
function OnGUI(){
GUI.Box (Rect (900, 570, 130, 25), Text);
}
``````

I Hope You Can Help Me

PlayerPrefs.SetInt(“Diamonds”, Diamond + PlayerPrefs.GetInt(“Diamonds”));

Sorry didnt see the first couple lines…I suggest instead of storing the diamonds in a member variable just use the playerprefs, like in your trigger fucntion. It could be you have multiple instances of the class in the scene and one is overriding the other.

here are the lines I would replace:

`````` Diamond +=  NumDiamonds;
Text = "Diamonds  :  " + Diamond;
``````

with:

`````` PlayerPrefs.SetInt("Diamonds", NumDiamonds + PlayerPrefs.GetInt("Diamonds"));//Diamond +=  NumDiamonds;
Text = "Diamonds  :  " + PlayerPrefs.GetInt("Diamonds");//Text = "Diamonds  :  " + Diamond;
``````