溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

[Unity3d for android]屏幕觸摸事件

發(fā)布時間:2020-07-03 19:11:20 來源:網(wǎng)絡(luò) 閱讀:388 作者:蓬萊仙羽 欄目:游戲開發(fā)

移動物體:

[csharp] view plaincopy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class example : MonoBehaviour {  
  5.     public float speed = 0.1F;  
  6.     void Update() {  
  7.         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {  
  8.             Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;  
  9.             transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);  
  10.         }  
  11.     }  
  12. }  


點擊碰撞克隆

[csharp] view plaincopy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class example : MonoBehaviour {  
  5.     public GameObject projectile;  
  6.     void Update() {  
  7.         int i = 0;  
  8.         while (i < Input.touchCount) {  
  9.             if (Input.GetTouch(i).phase == TouchPhase.Began)  
  10.                 clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject;  
  11.               
  12.             ++i;  
  13.         }  
  14.     }  
  15. }  


 

===================

[csharp] view plaincopy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class example : MonoBehaviour {  
  5.     public GameObject particle;  
  6.     void Update() {  
  7.         int i = 0;  
  8.         while (i < Input.touchCount) {  
  9.             if (Input.GetTouch(i).phase == TouchPhase.Began) {  
  10.                 Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);  
  11.                 if (Physics.Raycast(ray))  
  12.                     Instantiate(particle, transform.position, transform.rotation) as GameObject;  
  13.                   
  14.             }  
  15.             ++i;  
  16.         }  
  17.     }  
  18. }  


 

TouchPhase Enumeration  

Describes phase of a finger touch.

Values

Began

A finger touched the screen.

Moved

A finger moved on the screen.

Stationary

A finger is touching the screen but hasn't moved.

Ended

A finger was lifted from the screen. This is the final phase of a touch.

Canceled

The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch.

 

 

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI