Because the Unity 4.6 has just released, the Ugui function of the relevant data is not very perfect, today just installed Unity 4.6, want to see if Ugui is good, then start learning today Ah!
1, create a new empty project.
2, open Unity's own UI system.
3, create Ui->canvas. Here I do not introduce more canvas, plainly is the layout. You'll find a lot more EventSystem (event System).
1,eventsystem is an object that sends input-based events to an application, whether it's a keyboard, mouse, touch, or custom input.
2,EventSystem consists of several components that send events.
Detailed introduction See: http://docs.unity3d.com/460/Documentation/ScriptReference/EventSystems.EventSystem.html
4, Next we build a panel (also not built, personal preferences), build a panel I feel easy to manage the space.
5, then get a button out, OK!
Suspension Effect:
5, Next we write a script to experiment with click events.
Method One:
usingUnityengine;usingSystem.Collections;usingUnityengine.ui; Public classtestclick:monobehaviour{//Use this for initialization voidStart () {Button btn= gameobject.getcomponent<button>();Btn.onClick.AddListener (click); } voidClick () {Debug.Log ("Mouse Click"); }}
Implementation results:
Method Two:
Experimental results:
It's not hard at all!
Let's learn a little bit further:
6, build a ButtonClick.cs
usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingunityengine.events; Public classButtonclick:monobehaviour {//Use this for initialization voidStart () {Button btn= gameobject.getcomponent<button>();Btn.onClick.AddListener (Delegate() { for(intI=0;i<Ten; i++) {OnClick (i); } }); } Public voidOnClick (intindex) {Debug.Log (index); }}
Experimental results:
is not commissioned can also use Ah, good, now learn to sell, we learn together!
Unity 4.6 Ugui Click events