button事件

(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的值就可以啦,必须是一边录一边改喔

今天暂时就这样了,之后会往后补充


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值