GameObject obj = Resources.Load("RankContent") as GameObject;
for (int i = 0; i < 5;i++ )
{
GameObject Rank = Instantiate(obj) as GameObject;
Rank.transform.parent = rankScrool;
GameObject name = Rank.transform.Find("RankUserName").gameObject;
GameObject image = Rank.transform.Find("RankClip").gameObject;
Rank.transform.localPosition = positionV3;
Text nameText = name.GetComponent<Text>();
Image imageClip = image.GetComponent<Image>();
//nameText.GetComponent<RectTransform>().sizeDelta = new Vector2(Screen.width / 5, Screen.height / 8);
//nameText.transform.localPosition = positionV3;
positionV3 += new Vector3(160, 0, 0);
nameText.fontSize = 20;
nameText.text = "第一名:小明";
}
Resources中读取prefab,动态生成控件
最新推荐文章于 2022-12-19 10:34:54 发布