Unity InvokeRepeating()不起作用

时间:2018-04-17 19:41:18

标签: c# unity3d

我的新点击游戏中有一个使用InvokeRepeating的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AutomineController : MonoBehaviour {

    static int WoodMiners = 0;
    static int StoneMiners = 0;
    public Text already_mining;
    public Text invalid_transaction;
    public Text too_many_miners;

    // Error message code 

    private IEnumerator TooManyMinersCore ()
    {
        already_mining.gameObject.SetActive (false);
        invalid_transaction.gameObject.SetActive (false);
        too_many_miners.gameObject.SetActive (true);
        yield return new WaitForSeconds (1.5f);
        too_many_miners.gameObject.SetActive (false);

    }

    // The code that does the actual mining

    private static void WoodMiner ()
    {
        Debug.Log("Here");
        ChopWood.Add ();
    }


    // The code that "hires" the miners

    public void HireWoodMiner ()
    {
        if (WoodMiners < 5) {
            WoodMiners += 1;
            InvokeRepeating("WoodMiner", 0.1f, 3.0f);
        } else {
            StartCoroutine(TooManyMinersCore());
        }
    }

}

由于某种原因,InvokeRepeating()不起作用 - 它应该在运行HireWoodMiner()方法时运行WoodMiner()方法。这是为什么?

0 个答案:

没有答案