移动物体:

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