u3d响应点击事件
来源:互联网 发布:点餐系统数据库设计 编辑:程序博客网 时间:2024/05/18 01:48
http://www.cnblogs.com/kenzi/p/3739517.html
25.Unity3D手机中Input类touch详解-Unity触屏事件解析到底(Twisted Fate)
首先贴一下Unity支持的模型文件类型,以前没有收集过。
Unity支持两种类型的3D文件格式:
1. 通用的“出口型”3D文件
如.fbx、.dae、.3ds、.dxf、.obj等文件格式。
2. 3D软件专用的3D文件格式
如Max, Maya, Blender,Cinema4D, Modo, Lightwave & Cheetah3D 等软件所支持的格式,如.MAX, .MB, .MA等等。
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接收。
1 static var aa:int; 2 function Update () { 3 if(Input.touchCount>0) 4 { 5 print(Input.touchCount); 6 } 7 } 8 function OnGUI() 9 {10 GUI.Label(Rect(34,34,34,34),"sdff");11 }
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());}
移动物体:
using UnityEngine;using System.Collections;public class example : MonoBehaviour { public float speed = 0.1F; void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0); } }}
点击碰撞克隆:
using UnityEngine;using System.Collections;public class example : MonoBehaviour { public GameObject projectile; void Update() { int i = 0; while (i < Input.touchCount) { if (Input.GetTouch(i).phase == TouchPhase.Began) clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject; ++i; } }}
点击屏幕,射线法发射一个粒子
using UnityEngine;using System.Collections;public class example : MonoBehaviour { public GameObject particle; void Update() { int i = 0; while (i < Input.touchCount) { if (Input.GetTouch(i).phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position); if (Physics.Raycast(ray)) Instantiate(particle, transform.position, transform.rotation) as GameObject; } ++i; } }}
using UnityEngine;using System.Collections;public class TestTouch : MonoBehaviour {static int clickTimes=0;// Use this for initializationvoid Start () {Debug.Log ( " you touch me please .... ");}// Update is called once per framevoid Update () {if (Input.touchCount > 0) {clickTimes++;//Debug.Log ( " \n \n you touch me please .... the time is " + clickTimes);if (Input.GetTouch (0).phase ==TouchPhase.Began){Debug.Log (" !!!!! touch begin ---------- ");}if (Input.GetTouch (0).phase == TouchPhase.Stationary ) {return;//Debug.Log (" !!!!! touch remove ---------- ");}if (Input.GetTouch (0).phase == TouchPhase.Moved) {//Debug.Log (" !!!!! touch remove ---------- ");}if (Input.GetTouch (0).phase == TouchPhase.Ended) {Debug.Log (" !!!!! touch end ---------- ");}if (Input.GetTouch (0).phase == TouchPhase.Canceled) {Debug.Log (" !!!!! touch canceled ---------- ");}print (Input.touchCount);Vector2 v2 = new Vector2 (Input.GetTouch (0).position.x, Input.GetTouch(0).position.y);//Debug.Log (" You touch me x:= " + v2.x + " y:= " + v2.y );}}}
阅读全文
0 0
- u3d响应点击事件
- U3D 对象响应鼠标点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- UIImageView响应点击事件
- LeetCode 674. Longest Continuous Increasing Subsequence
- [LeetCode] 073: Permutations II
- [LeetCode] 074: Plus One
- linux iic驱动编程之一 基本的编程思想
- [LeetCode] 075: Populating Next Right Pointers in Each Node
- u3d响应点击事件
- [LeetCode] 076: Populating Next Right Pointers in Each Node II
- 《利用 Python 进行数据分析》读书笔记
- [LeetCode] 077: Pow(x, n)
- [转载] 从Trie树到后缀树
- 薛定谔的猫
- Windows python3下安装scrapy爬虫框架的完美方案
- [面试题] 随机数相关面试题(1)
- [面试题] 随机数相关面试题(2)