Unity 2D - 敌人为何不能制造?

时间:2016-11-10 11:46:45

标签: unity3d unity5

我正在制作一个正在运行的游戏,但我面临着一个大问题。 在舞台上,创造了障碍。但过了一段时间,团结并没有成为新的障碍。为什么会这样?

public class GameManager : MonoBehaviour {
    public float waitingTime = 1.5f;
    public static GameManager manager;
    public bool ready = true;
    public GameObject cactus;
    float time = 0;

    // Use this for initialization
    void Start () {
        manager = this;
    }

    // Update is called once per frame
    void Update () {
        time += Time.deltaTime;
        //Debug.Log(time);
        if(time>2f && ready==true)
        {
            ready = false;
            time = 0;
            InvokeRepeating("MakeCactus", 1f, waitingTime);
        }
    }
    void MakeCactus()
    {
        Instantiate(cactus);
    }
   public void GameOver()
    {
        //CancelInvoke("MakeCactus");
        iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("x", 0.2, "y", 0.2, "time", 0.5f));
    }
}

1 个答案:

答案 0 :(得分:1)

根本不需要Update方法。因为你正在使用它只是为了延迟你的产卵。您的代码可以像这样重写:

public class GameManager : MonoBehaviour 
{
    public float waitingTime = 1.5f;
    public static GameManager manager;
    public GameObject cactus;

    void Awake() 
    {
        manager = this;
        InvokeRepeating("MakeCactus", 3f, waitingTime);
    }

    void MakeCactus()
    {
        Instantiate(cactus);
    }

    public void GameOver()
    {
        //CancelInvoke("MakeCactus");
        iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("x", 0.2, "y", 0.2, "time", 0.5f));
    }
}

希望这能解决问题

相关问题