Hello!
The gold earned during the game is displayed at the top of the screen.
If Game Over happens, the Game Over panel will appear and the total gold earned in the game is displayed on this panel. If the player presses the 2X button, they will earn double gold after watching the ad.
At the same time, 2X gold will be written on the Game Over panel because the advertisement is watched.
And all the collected gold is displayed on the main menu scene.
I tried to do this with playerprefs, I don't know why but wrong actions occur.
For example, after watching the ad I won 5 gold in the game, the total amount of gold earned should be 10, but it is 9. In the main menu scene, 8 gold is added on top of the previous gold.
How can I resolve this situation?
I need your help.
Thanks!
My game:
private void OnCollisionStay(Collision collision)
{
if (collision.gameObject.tag == "Gold")
{
PlayerPrefs.SetFloat("Gold", gold);
PlayerPrefs.Save();
gold ++;
goldText.text="Gold: " + gold;
Destroy(collision.gameObject);
}
}
Codes for 2X gold rewarded:
public void videoyuizlediOduluHaketti(object sender, Reward args)
{
gold= 2 * PlayerPrefs.GetFloat("Gold");
goldText2x.text="Gold: " + gold;
PlayerPrefs.SetFloat("Gold",PlayerPrefs.GetFloat("Gold") + gold);
}
To show total gold amount on Game Over Panel:
void Start()
{
gold=PlayerPrefs.GetFloat("Gold");
goldText.text="Gold: " + gold;
}
Total gold amount on menu scene:
void Start()
{
//total gold amount
PlayerPrefs.SetFloat("Gold",PlayerPrefs.GetFloat("Gold") + gold);
gold=PlayerPrefs.GetFloat("Gold");
goldText.text="Gold: " + gold;
}
Game Over Panel:
after game over total gold=5
on game over panel total gold=2708: (But it should be 5. After rewarded ads it will be 10)
![alt text][1]
[1]: /storage/temp/183916-ekran-alıntısı.png
↧