[Unity3d for android]屏幕触摸事件
admin
2023-01-20 20:00:55
0

移动物体:

[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.

 

 

相关内容

热门资讯

今日重大发现“杭州麻将.怎么开... 网上科普关于“杭州麻将有没有挂”话题很是火热,小编也是针对杭州麻将作*弊开挂的方法以及开挂对应的知识...
【第一财经】“白金岛游戏.怎么... 您好:白金岛游戏这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游...
玩家最新攻略“奕福麻将.有没有... 家人们!今天小编来为大家解答奕福麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
【今日要闻】“麻友圈2贵阳捉鸡... 有 亲,根据资深记者爆料麻友圈2贵阳捉鸡是可以开挂的,确实有挂(咨询软件...
今日重大发现“聚友互娱.怎么开... 有 亲,根据资深记者爆料聚友互娱是可以开挂的,确实有挂(咨询软件无需打开...
重磅消息“炫龙牛牛.到底有挂吗... 您好:炫龙牛牛这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...
今日重磅消息“皇豪众娱牛牛.辅... 有 亲,根据资深记者爆料皇豪众娱牛牛是可以开挂的,确实有挂(咨询软件无需...
终于明白“经典联盟牛牛.开挂器... 家人们!今天小编来为大家解答经典联盟牛牛透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里...
重磅消息“麻友圈2贵阳捉鸡.可... 您好:麻友圈2贵阳捉鸡这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在...
暗号“奥特曼”可进张学友、陈奕... 极目新闻记者 孙婷婷奥特曼贴纸当暗号,可直接进场看张学友、陈奕迅演唱会?只要身份证上贴个奥特曼,保安...