簡體   English   中英

我想創建一組場景索引並在需要時使用它。 問題是我不知道如何創建數組本身

[英]I want to create an array of scene indexes and use it, when i need. The problem is that i don't know how to create the array itself

我做了這個

    public int[] sceneIndex;
    public Text[] texts;
    
    IEnumerator ChoosingModes()
    {
        string[] modes = new string[] { "Cocks", "Tanks", "Cars" };
        sceneIndex = new int[] { };
        for (int i = 0; i < 5; i++)
        {
            int x = Random.Range(0, modes.Length);
            texts[i].text = modes[x];
            sceneIndex[i] = x + 3;
            yield return new WaitForSeconds(0.75f);
        }
    }

它顯然不起作用,如何處理我的名為“sceneIndex”的數組?

當你做sceneIndex = new int[] { }; ,您將sceneIndex的長度鎖定為 0。相反,請嘗試使用sceneIndex = new int[number or scenes]; (將sceneIndex的長度鎖定為您擁有的場景數)或什么都不做。 由於數組是公開的,您可以在檢查器中設置值,而不必在代碼中定義它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM