Hello,
I have a script, which will display on the menu your total coins.
In my game, I have a score, and when you die, the score must be updated to your coins.
Now what I have done, is when you get a point for your score, it also needs to be updated directly to the total coins. So the same OnTriggerEnter2D function.
This is my coins script:
public static Coins C;
public Text coinsText;
public int coins;
// Use this for initialization
void Start () {
C = this;
coinsText.text = " " + coins;
PlayerPrefs.SetInt ("coins",1);
Update();
}
// Update is called once per frame
void Update () {
Score.HS.OnTriggerEnter2D ();
coins = PlayerPrefs.GetInt("coins");
}
And this is my Score script:
public static Score HS;
public Text scoreText;
public Text HighScore;
public int krolschValue;
public int score;
Coins int coins;
int highScore;
void start () {
HS = this;
score = 0;
UpdateScore ();
highScore = PlayerPrefs.GetInt("HighScore1",1);
}
public void OnTriggerEnter2D () {
score += krolschValue;
coins += krolschValue;
UpdateScore ();
}
public void UpdateScore () {
scoreText.text = "X " + score;
HighScore.text = "HighScore: " + highScore;
}
public void CheckHighScore()
{
if(score > highScore)
{
Debug.Log ("Saving Score");
PlayerPrefs.SetInt("HighScore1",score);
}
}
Now I want the public int coins, from the coin script to the score script, so I can set into the OnTriggerEnter2D function that the coins also should get the value from the score on every point you get.
What I have right now doesn’t work, I have set Coins int coins, from the coins script.