最近写了一个跑酷游戏,总结下里面的知识点:O(∩_∩)O~

using UnityEngine;
using System.Collections; public class Demo : MonoBehaviour
{
public Vector3 lastMonseDown; /// <summary>
/// 判断手指触摸的方向
/// </summary>
/// <returns></returns>
TouchDir GetTouchDir()
{
//记录第一次手指点击的坐标点
if (Input.GetMouseButtonDown())
{
lastMonseDown = Input.mousePosition;
} //UICamera.hoveredObject防止NGUI点击穿透问题
if (Input.GetMouseButtonUp() && UICamera.hoveredObject == null)
{
//结束坐标-开始坐标
Vector3 mouseUp = Input.mousePosition;
Vector3 touchOffset = mouseUp - lastMonseDown; //滑动超过50像素,算一次正确的滑动
if (Mathf.Abs(touchOffset.x) > || Mathf.Abs(touchOffset.y) > )
{
if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x > )
{
return TouchDir.Right;
}
else if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x < )
{
return TouchDir.Left;
}
else if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.y > )
{ return TouchDir.Top;
}
else if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.y < )
{ return TouchDir.Bottom;
}
}
else
{
return TouchDir.None;
}
} return TouchDir.None;
} } /// <summary>
/// 触摸的方向
/// </summary>
public enum TouchDir
{
None,
Left,
Right,
Top,
Bottom
}

Unity 手指触摸的方向(单手)的更多相关文章

  1. Mac使用技巧总结-如何独立设置Mac触摸板方向和鼠标滚轮方向?

    Mac使用技巧总结 如何独立设置Mac触摸板方向和鼠标滚轮方向? 苹果Macbook的使用者都知道,Mac自带的触控板非常好用,不仅支持多手势操控,而且手感极佳,使用流畅. 但是如果对鼠标的焦距有高有 ...

  2. jquery手指触摸滑动放大图片的方法(比较靠谱的方法)

    jquery手指触摸滑动放大图片的方法(比较靠谱的方法) <pre><!DOCTYPE html><html lang="zh-cn">< ...

  3. [转]Unity 3D旋转矢量方向及二维平面基于一点选择另一点(Rotate a Vector3 direction & Rotate a point about another point in 2D )

    http://specialwolf.blog.163.com/blog/static/124466832201301332432766/ ****************************** ...

  4. Unity中用触摸控制物体旋转和放大

    using UnityEngine;using System.Collections;using System.IO; public class ScaleAndRotate : MonoBehavi ...

  5. Unite 2017 | Unity引擎发展四大方向

    Unite 2017 Shanghai已落幕,今天为大家分享本次大会备受关注的Keynote主题演讲.本次大会Keynote主题演讲聚焦了Unity全球领导团队,包括Unity创始人David Hel ...

  6. Xenko基础API笔记3- Pointers指针设备屏幕上点对应的手指触摸。

    样本这里是一个简单的示例程序,跟踪目前在屏幕上的指针和打印他们的位置.访问输入字段,类继承自@ SiliconStudio.Xenko.脚本的类. public override async Task ...

  7. Unity 手指上下左右滑动的判定

    using UnityEngine; using System.Collections; public class jarodInputController : MonoBehaviour { pri ...

  8. wpf 手指触摸图片放大缩小 设置放大缩小值

    xaml代码: <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/w ...

  9. 【转】Android-Input 触摸设备

    https://source.android.com/devices/input/touch-devices 触摸设备 Android 支持各种触摸屏和触摸板,包括基于触控笔的数字化板. 触摸屏是与显 ...

随机推荐

  1. iOS 3DES加密 和 java 3DES 解密

    首先进入头文件: #import <CommonCrypto/CommonDigest.h> #import <CommonCrypto/CommonCryptor.h> #i ...

  2. 判断一个int 型整数 是否为回文数

    leetcode 上的题目 Determine whether an integer is a palindrome. Do this without extra space. 由于不能使用额外空间, ...

  3. XSS第二节,XSS左邻右舍

    昨天的文章中引用了OWASP2013年的江湖排名,今天来看一下TOP中XSS的左邻右舍都是谁,先看一下他们的大名,再进一步介绍 [以下主要翻译自https://www.owasp.org/index. ...

  4. pat 1049 Counting Ones

    要统计1到N之间‘1’的个数,如数11包含2个1.所以当N=12时,答案为5. 思想: 找规律,假设ans[N]表示1到N的‘1’的个数,则有a[100]=(a[10]-1)*9+10+a[10]-1 ...

  5. [Unit Testing] Directive testing, require parent controller

    function getCompiledElement() { $scope.chart = { additional: "$ 1.56 / per minute", text: ...

  6. 1. GDAL与OpenCV2.X数据转换(适合多光谱和高光谱等多通道的遥感影像)

    一.前言 GDAL具有强大的图像读写功能,但是对常用图像处理算法的集成较少,OpenCV恰恰具有较强的图像处理能力,因此有效的结合两者对图像(遥感影像)的处理带来了极大的方便.那么如何实现GDAL与o ...

  7. doT.js 声明

    // 模板引擎配置项 var tmplOptions = { evaluate: /\{\{([\s\S]+?\}?)\}\}/g, interpolate: /\{\{=([\s\S]+?)\}\} ...

  8. FullCalendar 的学习笔记(二)

    下面是一个.NET webForm的具体列子 注意引用了artDialog 以及异步请求数据的json格式字符串 <html xmlns="http://www.w3.org/1999 ...

  9. NSString / NSMutableString 字符串处理,常用代码 (实例)

    http://blog.csdn.net/likendsl/article/details/7417878 Objective-C 中核心处理字符串的类是 NSString 与 NSMutableSt ...

  10. 真机调试以及“Could not find Developer Disk Image”问题解决方案

    真机测试步骤 1.运行Xcode,Xcode打开后,点左上角菜单'Xcode',点'Preferences'. 2.在打开的窗口中,点'Accounts',切换到账号页,然后点下面的'+'号,在弹出菜 ...