1
using UnityEngine;
System.Collectionsを使用します。 UnityEngine.UIを使用している ;Unity PlayerPrefsは1アイテムのみをすべて保存します
パブリッククラスItemScript:MonoBehaviour {
public Click click;
public Text MPSInfo;
public ItemManager[] items;
void Start()
{
LoadItems();
StartCoroutine(AutoTick());
}
void Update()
{
MPSInfo.text = "Money/Sec: " + MoneyPerSec();
}
public int MoneyPerSec()
{
int tick = 0;
foreach(ItemManager item in items)
{
tick += item.count * item.tickValue;
PlayerPrefs.SetInt(item.ItemName + "Count", item.count);
PlayerPrefs.SetFloat(item.ItemName + "Cost", item.cost);
print(item.ItemName);
print(item.count);
print(item.cost);
}
return tick;
}
public void AutoMoneyPerSec()
{
Click.money += MoneyPerSec();
}
IEnumerator AutoTick()
{
while(true)
{
AutoMoneyPerSec();
yield return new WaitForSeconds(1);
}
}
public void LoadItems()
{
foreach(ItemManager item in items)
{
item.count = PlayerPrefs.GetInt(item.ItemName + "Count");
item.cost = PlayerPrefs.GetFloat(item.ItemName + "Cost");
print(item.ItemName);
print(item.count);
print(item.cost);
}
}
}
私はこのスクリプトを持っている、と私は2つの項目は試験のために、設定したが、Playerprefsのみ秒間とするための第二項目を保存最初の項目。彼らは同じコストであり、数えます。
私は2つのアイテムを入れました。別々のボタンです。 – Kalip
'PlayerPrefs.DeleteAll()'を使用して、両方ともコストが0になりました。 – Kalip
ItemscriptはMPSInfoテキストにあります。アイテム。 – Kalip