首页 > 解决方案 > 根据多维数组的值实例化预制件(C# UNITY)

问题描述

大家好,我只是想问一下是否可以根据您的值实例化预制件Multidimensional Array,例如我有这些数据。

10 20 11

00 21 10

00 00 00

00 00 00

00 00 00

00 00 00

现在这是我的代码

string road1 = "";
    for (int y = 0; y < bsb.ArrBigRoad.GetLength(0); y++)
    {
        for (int x = 0; x < bsb.ArrBigRoad.GetLength(1); x++)
        {
            road1 += string.Format("{0:D2}", bsb.ArrBigRoad[y, x] / 100);
            road1 += ".";
        }
        road1 += "\n";
    }
Debug.Log(road1);

现在我正在使用Label这样的方式打印它

[SerializeField] public UILabel info_scores_bigroad;

info_scores_bigroad.text = road1;

标签: c#unity3d

解决方案


谢谢洛坦,我所做的是这样的

SetScore.cs

public void Set( int score )
{
    int who = score / 1000;

    if (who == 1)
    {
        NGUITools.SetActive(obj_player, true );
        NGUITools.SetActive(obj_banker, false);
    }
    else if( who == 2)
    {
        NGUITools.SetActive(obj_player, false);
        NGUITools.SetActive(obj_banker, true);
    }
    else
    {
        NGUITools.SetActive(obj_player, false);
        NGUITools.SetActive(obj_banker, false);

        NGUITools.SetActive(lbl_tie_no.gameObject, false);
        NGUITools.SetActive(spr_playerPair.gameObject, false);
        NGUITools.SetActive(spr_bankerPair.gameObject, false);
        return;
    }
}

然后像这样图案化我在二维数组上的内容

游戏.cs

public IEnumerator ShowScoreBoard_BigRoad(int[,]  arrBigRoad)
{
    NGUITools.DestroyChildren(pos_bigroad);

    for (int y = 0; y < arrBigRoad.GetLength(0); y++)
    {
        for (int x = 0; x < arrBigRoad.GetLength(1); x++)
        {
            int score = arrBigRoad[y, x];

            GameObject o = Instantiate(prefab_bigroad) as GameObject;
            o.transform.SetParent(pos_bigroad);
            o.transform.localScale = Vector3.one;

            o.transform.localPosition = new Vector3(x * SX_, y* SY_, 0);
            NGUITools.SetActive(o, true);

            // 1011, 2000, 3000, 

            bsbBigRoad s = o.GetComponent<bsbBigRoad>();
            s.Set(score);
        }
    }

    yield break;
}

不过还是谢谢。:)


推荐阅读