C# 在统一的精灵上书写文字
我想用统一的精灵创建一个网格。每个单元格上都应该有一个数字 应该是这样的 我的网格看起来是这样的 所以我生成了细胞,并将它们添加到一个名为 地图C# 在统一的精灵上书写文字,c#,unity3d,C#,Unity3d,我想用统一的精灵创建一个网格。每个单元格上都应该有一个数字 应该是这样的 我的网格看起来是这样的 所以我生成了细胞,并将它们添加到一个名为 地图 private GameObject cellpreaf; 私有常量int单元格计数=10;//创建100个单元格 私有常量int单元计数Y=10; 专用常量浮点数间距=1.1f;//间隔小 私有列表单元格=新列表();//把所有细胞都储存在这里 私有常量int NUM\u RANGE\u MIN=1;//单元格值范围 私有常量int NUM_RA
private GameObject cellpreaf;
私有常量int单元格计数=10;//创建100个单元格
私有常量int单元计数Y=10;
专用常量浮点数间距=1.1f;//间隔小
私有列表单元格=新列表();//把所有细胞都储存在这里
私有常量int NUM\u RANGE\u MIN=1;//单元格值范围
私有常量int NUM_RANGE_MAX=10;
私有void Start()
{
CellPrefact=Resources.Load(StringCollection.CELL)作为游戏对象;
对于(int x=0;x |
每个单元格都附加了这个脚本
private Text txtCellValue;
private int cellValue;
public void InitCell(int value)
{
txtCellValue = transform.GetChild(0).GetChild(0).GetComponent<Text>(); // get the text component of the cell
cellValue = value; // set the value
txtCellValue.text = cellValue.ToString(); // update the GUI
}
私有文本txtCellValue;
私人价值;
公共void InitCell(int值)
{
txtCellValue=transform.GetChild(0).GetChild(0).GetComponent();//获取单元格的文本组件
cellValue=value;//设置值
txtCellValue.text=cellValue.ToString();//更新GUI
}
因此,在层次结构中,每个单元都被添加到“映射”中,并获得了自己的层次结构
画布设置为“按屏幕大小缩放”,文本本身具有这些设置
我只想在这个精灵上写下单元格的值。也许有更干净的方法?
如果有人能帮我修一下就好了 您将为画布选择渲染模式“世界”。然后设置比例和宽度/高度值 此外,您还将记住有关图层排序的信息。画布层将比精灵渲染器大,若你们并没有为UI使用单独的相机
private Text txtCellValue;
private int cellValue;
public void InitCell(int value)
{
txtCellValue = transform.GetChild(0).GetChild(0).GetComponent<Text>(); // get the text component of the cell
cellValue = value; // set the value
txtCellValue.text = cellValue.ToString(); // update the GUI
}