分享一下ngui 代码创建button的效果,如下图
- using UnityEngine;
- using System.Collections;
- public class CreatButton : MonoBehaviour
- {
- public GameObject buttonPrefab;
- // Use this for initialization
- void Start ()
- {
- }
- // Update is called once per frame
- void Update ()
- {
- }
- void CreatNewBotton()
- {
- GameObject button = Instantiate(buttonPrefab, transform.position, Quaternion.identity) as GameObject;
- button.transform.parent = transform;
- button.transform.localScale = new Vector3(1,1,1);
- gameObject.GetComponent<UIGrid>().repositionNow = true;
- }
- }