加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Unity 屏幕触摸事件

(2016-08-27 10:13:53)
分类: Coder

该文内容摘抄整理:

移动物体:

[csharp] view plain copy
  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 && 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 plain copy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class example MonoBehaviour  
  5.     public GameObject projectile;  
  6.     void Update()  
  7.         int 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 plain copy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class example MonoBehaviour  
  5.     public GameObject particle;  
  6.     void Update()  
  7.         int 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.

 

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有