NGUI的代码控制

来源:互联网 发布:剑灵捏脸数据fate 编辑:程序博客网 时间:2024/05/22 06:20

NGUI的代码控制

1、代码操作NGUI

using UnityEngine;using System.Collections;public class ChangeColor : MonoBehaviour {// Use this for initializationvoid Start () {        UISprite theSprite = this.GetComponent<UISprite>();        theSprite.color = Color.red;}// Update is called once per framevoid Update () {}}



与此类似:

UILabel、UISprite、UITexture、UIButton、UIGrid、UISlider、UIToggle、UIInput、UIPanel、UICamera。等


都可以有用类似:

UISprite theSprite = this.GetComponent<UISprite>();

得到。


2、动态加载UI元素



using UnityEngine;using System.Collections;public class LoadPrefab : MonoBehaviour {    public GameObject prefab;// Use this for initializationvoid Start () {        GameObject newObj = NGUITools.AddChild(this.gameObject, prefab);}// Update is called once per framevoid Update () {}}




0 0
原创粉丝点击