您当前的位置: 首页 >  unity

程序员正茂

暂无认证

  • 6浏览

    0关注

    283博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity批量创建按钮

程序员正茂 发布时间:2016-10-21 11:30:28 ,浏览量:6

1.调用其他物体脚本的方法:

GameObject.Find("脚本所在物体名").GetComponent().函数名();
2.批量创建按钮
public class CreateRecentCourseBtn : MonoBehaviour {
	private string[] subjects = {"牛顿运动定律", "材料物理", "食品化学", "基础医学"};
	public Button BtnRecentCoursePrefab;
	// Use this for initialization
	void Start () {
		for(int i = 0; i < subjects.Length; i++)
		{
			Button obj = Instantiate(BtnRecentCoursePrefab);
			obj.transform.SetParent(transform);
			obj.GetComponent().anchoredPosition3D = new Vector3(0,0,0);//不设置的话可能跑到其他地方去了
			obj.GetComponent().localScale = new Vector3(1,1,1);//不设置的话变大了
			Text btnText =	obj.GetComponentInChildren();
			btnText.text = ""+subjects[i]+"";//改变按钮文件颜色
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
关注
打赏
1660743125
查看更多评论
立即登录/注册

微信扫码登录

0.0360s