How to save money
Hello, I'm making a mobile game and I don't know how to save the amount of money I got. I want when I exit the game, the game will be saved and when I join again I have the same amount of money I had before. (like Temple run, Subway surf etc...)
Thanks.
THE COIN SCRIPT
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinsScript : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
private void OnTriggerEnter(Collider other)
{
if(other.name == "Player")
{
other.GetComponent<PlayerMotor>().coins++;
anim.SetTrigger("Collected");
Destroy(gameObject);
}
}
}
Comment
Answer by KabukiDanshi · Feb 09, 2019 at 12:36 AM
I don't know if you solved it already, but i think you need PlayerPrefs. You can use it to store coins or highscore and it's saved even if you exit the game.