Unity3D手机中Input类touch详解
2015-04-14 07:25
369 查看
Unity3D手机中Input类touch详解:
1.Input.touchCount 触摸随之增长,一秒50次增量。
2.Input.GetTouch(0).phase==TouchPhase.Moved 手指滑动中最后一帧滑动的状态是运动的。
3.TouchPhase 触摸的几个状态。
4.Touch.deltaPosition 增量位置(Input.GetTouch(0).deltaPosition)最后一帧滑动的值,只返回xy轴坐标,也可用vector3(z轴为0),所以一般用vector2接收。
static var aa:int;
function Update () {
if(Input.touchCount>0)
{
print(Input.touchCount);
}
}
function OnGUI()
{
GUI.Label(Rect(34,34,34,34),"sdff");
}
touchCount指的是触摸帧的数量。要注意的是:touch事件 只能在模拟器或者真机上运行(已测试通过),大约一秒钟touch不放。touchCount+50次左右。2.Input.touches 触摸列表。
// Prints number of fingers touching the screen
//输出触摸在屏幕上的手指数量
function Update () {
var fingerCount = 0;
for (var touch : Touch in Input.touches) {
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
fingerCount++;
}
if (fingerCount > 0)
print ("User has " + fingerCount + " finger(s) touching the screen");
}
3.让cube随着touch 移动代码:
static var count:int; //定义touchCount数
var particle_:GameObject;//定义存放cube对象
var touchposition:Vector3; //存储移动三维坐标值
function Update () {
if(Input.touchCount>0)
{
count+=Input.touchCount;}
if((Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Moved)) //[color=Red]如果点击手指touch了 并且手指touch的状态为移动的[/color]
{
touchposition=Input.GetTouch(0).deltaPosition; //[color=Red]获取手指touch最后一帧移动的xy轴距离[/color]
particle_.transform.Translate(touchposition.x*0.01,touchposition.y*0.01,0);//[color=Red]移动这个距离[/color]
}}
function OnGUI()
{
GUI.Label(Rect(10,10,100,30),"cishu:"+count.ToString());
GUI.Label(Rect(10,50,100,30),touchposition.ToString());
}
1.Input.touchCount 触摸随之增长,一秒50次增量。
2.Input.GetTouch(0).phase==TouchPhase.Moved 手指滑动中最后一帧滑动的状态是运动的。
3.TouchPhase 触摸的几个状态。
4.Touch.deltaPosition 增量位置(Input.GetTouch(0).deltaPosition)最后一帧滑动的值,只返回xy轴坐标,也可用vector3(z轴为0),所以一般用vector2接收。
static var aa:int;
function Update () {
if(Input.touchCount>0)
{
print(Input.touchCount);
}
}
function OnGUI()
{
GUI.Label(Rect(34,34,34,34),"sdff");
}
touchCount指的是触摸帧的数量。要注意的是:touch事件 只能在模拟器或者真机上运行(已测试通过),大约一秒钟touch不放。touchCount+50次左右。2.Input.touches 触摸列表。
// Prints number of fingers touching the screen
//输出触摸在屏幕上的手指数量
function Update () {
var fingerCount = 0;
for (var touch : Touch in Input.touches) {
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
fingerCount++;
}
if (fingerCount > 0)
print ("User has " + fingerCount + " finger(s) touching the screen");
}
3.让cube随着touch 移动代码:
static var count:int; //定义touchCount数
var particle_:GameObject;//定义存放cube对象
var touchposition:Vector3; //存储移动三维坐标值
function Update () {
if(Input.touchCount>0)
{
count+=Input.touchCount;}
if((Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Moved)) //[color=Red]如果点击手指touch了 并且手指touch的状态为移动的[/color]
{
touchposition=Input.GetTouch(0).deltaPosition; //[color=Red]获取手指touch最后一帧移动的xy轴距离[/color]
particle_.transform.Translate(touchposition.x*0.01,touchposition.y*0.01,0);//[color=Red]移动这个距离[/color]
}}
function OnGUI()
{
GUI.Label(Rect(10,10,100,30),"cishu:"+count.ToString());
GUI.Label(Rect(10,50,100,30),touchposition.ToString());
}
相关文章推荐
- unity3D 实现手机的双指触控和Input类touch详解
- unity3d 手机中Input类中touch详解_教程
- 25.Unity3D手机中Input类touch详解-Unity触屏事件解析到底(Twisted Fate)
- unity3d 手机中Input类中touch详解_教程
- 手机移动端浏览器touch事件系列详解
- Unity3D 游戏引擎之游戏对象的访问绘制线与绘制面详解(十七)
- Unity3D - 详解Quaternion类
- Unity3D - 详解Quaternion类(一)
- unity3d开发实战《啪啪三国》技术详解!
- [手机取证] iOS 4 (iPhone/iPad/iPod Touch) 密码破解
- 关于sencha touch 用phonegap打包后,docked悬停的组件被手机软键盘遮挡的解决方法
- 关于sencha touch在华为、红米等部分手机下hide事件失效,msgbox无法关闭的解决方案(已更新最新解决方案)
- 适用于Ubuntu手机的Ubuntu Touch OTA-5发布,新的Morph浏览器
- 高效、稳定、可复用——手机淘宝主会场框架详解
- touch.js详解
- [置顶] unity3d 5.0以上打包安卓apk部分手机黑屏问题,尤其魅族手机
- 移动端click时间、touch事件、tap事件详解
- Linux学习之三(根文件系统详解及文件管理mkdir,touch)
- JAVA手机软件程序JAR文件和JAD文件详解
- Win10/WP10手机系统预览版更新内容汇总(图文详解)