茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1675425 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
MODOCA_0032.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2015/3/28 11:41:28

Unity3D 手機中 Input 類 touch 詳解 Unity觸屏事件解析

首先貼一下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)) //如果點擊手指touch了 並且手指touch的狀態為移動的
{
touchposition
=Input.GetTouch(0).deltaPosition; //獲取手指touch最後一幀移動的xy軸距離
particle_.transform.Translate(touchposition.x*0.01,touchposition.y*0.01,0);//移動這個距離
}}
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;
}
}
}


原文出處:25.Unity3D手机中Input类touch详解-Unity触屏事件解析到底(Twisted Fate) - Twisted Fate Gargamel - 博客园
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|