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 () {
}
}