I’m working on a game where my main character is collecting “treats” which is the in-game currency. I have a script attached to my character to collect the treats when he collides with one and it destroys the treat game object. I have a GUI text set up that shows the amount of treats collected throughout the level and I would like to set up a database that keeps track of the treats collected over time. The treats collected can then be used to unlock new levels, purchase new characters, etc… Here is my script, any help/advice on where/how I can set up the playerprefs to save/store the treats collected would be greatly appreciated, thanks in advance.
using UnityEngine;
using System.Collections;
public class CollectTreat : MonoBehaviour {
public GUIText treatCount;
private int treats;
private int treatValue = 0;
void Start ()
{
treats = 0;
UpdateTreats ();
}
void getTreat (Collider2D treatCollider)
{
treats++;
AddScore (treatValue);
Destroy(treatCollider.gameObject);
}
void OnTriggerEnter2D (Collider2D collider)
{
if (collider.gameObject.CompareTag("TreatController"))
getTreat(collider);
}
public void AddScore (int newTreatValue)
{
treats += newTreatValue;
UpdateTreats ();
}
void UpdateTreats ()
{
treatCount.text = "" + treats;
}
}