(1)button自定义事件:
<span style="font-size:14px;">using UnityEngine;
using System.Collections;
public class Button : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
//开始按钮
if(GUI.Button(new Rect(0,10,100,30),"press me "))
{
//System.Console.WriteLine("hello world");
Application.LoadLevel("pratice");<span style="color:#ff0000;">//要跳转的界面</span>
// Debug.Log("up.up");
}
}
}</span>
如图:
按下去就跳转,直接绑定到main camera里就可以啦
(2)button控件事件
右键UI->Button在视图面板获得button
然后在main camera里建立一个c#文件,代码如下:
using UnityEngine;
using System.Collections;
public class scripts2 : MonoBehaviour {
// Use this for initialization
public void OnClick()
{
Application.LoadLevel("pratice");
}
}
然后在button里拖动main camera,如图:
然后选其中的OnClick就可以啦,可以多个拖动多个绑定事件
(3)button的Animation动画事件
添加Animator,以及在Transition中选Animation,要记得保存Auto Generate Animation(this),方便在其他的按钮中的Animator中拖动保存的(this)到Controller里
然后点击Window->Animation如图:
在Normal有很多属性,选其中的Highlighted(高亮),然后点红色的圆圈处开始录,在Add Property任意添加一个来添加效果,若要是改变scale的话,直接在Rect Transform里改变scale的值就可以啦,必须是一边录一边改喔
今天暂时就这样了,之后会往后补充