c# - 根据多维数组的值实例化预制件(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;
解决方案
谢谢洛坦,我所做的是这样的
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;
}
不过还是谢谢。:)
推荐阅读
- javascript - 来自按钮的 Javascript API 调用未将值返回到隐藏字段
- javascript - 是否可以将 js 字符串转换为日期以将其上传到 SQL 数据库?
- swift - 如何按日期过滤核心数据项?
- node.js - 即使抛出错误,异步函数也会以代码 0 退出
- python - 获取字典Python中具有特定值的所有键
- data-processing - 启动模型创建后不久显示“数据处理失败”的几个模型
- presto - Presto Sql-多个联合语句-语句太大(分析时堆栈溢出)
- c# - Titanium Web 代理 - 无法修改请求正文
- javascript - 赛普拉斯:获取“TypeError”,同时从 Page 对象类函数返回值
- ios - webview_flutter 在 iOS 中存档时导致问题