GameObject B = new GameObject();
B.transform.parent = A.transform;//A是一个canvas
B.AddComponent<Text>();
B.GetComponent<Text>().text = "XX";
上述代码运行后,文字“XX”无法显示,因为字体未设置。手动设置为默认字体之后会显示XX。
我试图用代码设置字体:
GameObject B = new GameObject();
B.transform.parent = A.transform;
B.AddComponent<Text>();
B.GetComponent<Text>().font = ;//这里怎么写?
B.GetComponent<Text>().text = "XX";
如上。font后面该怎么写?默认字体是Arial。直接写【B.GetComponent<text>().font = "Arial";】会报错,说无法把字符串转化成Font。</text>