您的位置:首页 > 产品设计 > UI/UE

NGUI的代码控制

2015-08-22 03:58 375 查看

NGUI的代码控制

1、代码操作NGUI

using UnityEngine;
using System.Collections;

public class ChangeColor : MonoBehaviour {

	// Use this for initialization
	void Start () {

        UISprite theSprite = this.GetComponent<UISprite>();
        theSprite.color = Color.red;
	}
	
	// Update is called once per frame
	void 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 initialization
	void Start () {
        GameObject newObj = NGUITools.AddChild(this.gameObject, prefab);
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: