Unity3D TouchScript 插件教程一

只是我的学习小记,谈不上教程,可是为了命中搜索引擎关键词,只好装逼了:),可能对于你们来讲太简单了吧,网上中文教程没搜到框架

,只好本身摸索了.ide

插件资源下载地址:https://www.assetstore.unity3d.com/#/content/7394学习

这是一款免费开源多点触摸框架.搜索引擎

点击查看原图

我是在Unity4.3上用的,并且项目是2D.spa

此次是给任意一个对象GameObject添加单击事件:插件

 

其实很简单的啦,只要给这个对象(如Cube)加个Collider组件(如Box Collider),而后再加个Press Gesture组件(菜单–Component–Touch Script–Gestures–Press Gesture).3d

接着新建个C#脚本(button.cs),拖到刚才新建的Cube上,脚本内容以下:code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 *
 *程序做者:
 *          蛐蛐
 *博客地址:
 *          http://xuyin.info
 *
 */
using UnityEngine;
using TouchScript.Events;
using TouchScript.Gestures;
public class button : MonoBehaviour
{
    private void Start()
    {
        if (GetComponent<PressGesture>() != null) GetComponent<PressGesture>().StateChanged += onPress;
    }
    private void onPress(object sender, GestureStateChangeEventArgs gestureStateChangeEventArgs)
    {
        Debug.Log("雅蠛蝶!!");
       //.....(单击后要作的事情)
    }
}

 

运行以后,打开控制台就能够看到:雅蠛蝶了!!对象

注意点:blog

 对新版的Unity3D4.3,因此必须用Component–Physics下的碰撞器,而不能用Component–Physics 2D下的.

相关文章
相关标签/搜索