Hello guys,
I’m coding a programm, where you can add money to a bank balance. So it is like “50€ from Mike” for example.
Then I need a historie, where you can see Who paid what.
So like “Mike - 50€”
I need an option to save the Names in a Playerpref.
But I need to save multiple names in one string.
So I don’t know how to do that and I cant find anything about it.
As you can see in my code: I’m from germany, so sorry for my bad english.
All in all I need to save “money3” and “names”
There is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Konto : MonoBehaviour
{
public InputField namen;
public InputField einzahlen;
public InputField auszahlen;
public Text kontostand;
public Text info;
public float money;
public float money2;
public float money3;
public string names;
// Update is called once per frame
void Update()
{
kontostand.text = money3.ToString() + " €";
money3 = PlayerPrefs.GetFloat("Kontostand");
}
public void Enter()
{
if (namen.text == "")
{
info.text = "Name erforderlich!";
}
if (einzahlen.text != "" && namen.text != "")
{
info.text = "";
if (einzahlen.text == "")
{
einzahlen.text = "0";
}
if (auszahlen.text == "")
{
auszahlen.text = "0";
}
money = float.Parse(einzahlen.text);
if (money > 0)
{
money3 += money;
Debug.Log(names);
names = namen.text;
SaveMoney();
}
einzahlen.text = "";
namen.text = "";
money2 = float.Parse(auszahlen.text);
if (money2 > 0)
{
money3 -= money2;
SaveMoney();
}
auszahlen.text = "";
}
if (auszahlen.text != "")
{
info.text = "";
if (einzahlen.text == "")
{
einzahlen.text = "0";
}
if (auszahlen.text == "")
{
auszahlen.text = "0";
}
money = float.Parse(einzahlen.text);
if (money > 0)
{
money3 += money;
Debug.Log(names);
names = namen.text;
SaveMoney();
}
einzahlen.text = "";
namen.text = "";
money2 = float.Parse(auszahlen.text);
if (money2 > 0)
{
money3 -= money2;
SaveMoney();
}
auszahlen.text = "";
}
}
public void Chang()
{
money3 += 50;
names = "Chang";
Debug.Log(names);
SaveMoney();
}
public void Nenat()
{
money3 += 50;
names = "Nenat";
Debug.Log(names);
SaveMoney();
}
public void Flo()
{
money3 += 50;
names = "Flo";
Debug.Log(names);
SaveMoney();
}
public void SaveMoney()
{
PlayerPrefs.SetFloat("Kontostand", money3);
}
}
Functions like Flo, Nenat, Chang,Enter are on Buttons
Thank you for helping me. I hope you can understand my bad english xD
MuffinLP