zoukankan      html  css  js  c++  java
  • Unity3D TouchScript 插件教程一

    只是个人学习小记,谈不上教程,但是为了命中搜索引擎关键词,只好装逼了:),可能对于大家来说太简单了吧,网上中文教程没搜到

    ,只好自己摸索了.

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

    这是一款免费开源多点触摸框架.

    点击查看原图

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

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

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

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

    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("雅蠛蝶!!");
           //.....(单击后要做的事情)
        }
    }

    运行之后,打开控制台就可以看到:雅蠛蝶了!!

    注意点:

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

  • 相关阅读:
    171. Excel Sheet Column Number (Easy)
    349. Intersection of Two Arrays (Easy)
    453. Minimum Moves to Equal Array Elements (Easy)
    657. Judge Route Circle (Easy)
    CSS笔记
    保存页面状态
    UI开发总结
    ubuntu 下配置munin
    反向代理配置
    JavaScript 高级程序设计第二版
  • 原文地址:https://www.cnblogs.com/TouchAfflatus/p/3536672.html
Copyright © 2011-2022 走看看