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,动态生成控件
最新推荐文章于 2024-07-28 12:34:42 发布
本文介绍如何在Unity中使用Instantiate方法动态生成排行榜UI元素,包括用户名和用户头像,并设置其位置和字体大小。
3078

被折叠的 条评论
为什么被折叠?



