Question by
0248 · Mar 10, 2017 at 07:20 AM ·
yieldyield waitforseconds
yeild return new WaitForSeconds doesn't work
public class GoldPerSec : MonoBehaviour {
public UnityEngine.UI.Text gpsDisplay;
public Click click;
public ItemManager[] items;
void Start()
{
StartCoroutine (AutoTick());
}
void Update()
{
gpsDisplay.text = GetGoldPerSec () + " gold/sec";
}
public int GetGoldPerSec()
{
int tick = 0;
foreach(ItemManager item in items)
{
tick += item.count * item.tickValue;
}
return tick;
}
public void AutoGoldPerSec()
{
click.gold += GetGoldPerSec();
}
IEnumerator AutoTick()
{
while(true)
{
AutoGoldPerSec();
yeild return new WaitForSeconds(1);
}
}
}
Comment