| 
 | 
 
 本帖最后由 夜行的猫仔 于 2013-4-23 14:59 编辑  
 
手机和PC不同,鼠标始终存在,移动的时候是平滑的,手机上手的点触会让摄像机突然偏转很大的角度。 
要制作一个手机上的摄像机其实很简单,修改系统的MouseLook脚本,增加一个判断,如果是触摸屏 
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved){ 
     //这里是MouseLook脚本原来的内容 
} 
这就OK了! 
CSDN上有一段鼠标右键旋转摄像机的代码,大家千万不要下载,错的。! 
以下是手机摄像机代码:- using UnityEngine;
 
 - using System.Collections;
 
  
- [AddComponentMenu("Camera-Control/Mouse Look")]
 
 - public class CameraControl : MonoBehaviour {        
 
  
-         public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
 
 -         public RotationAxes axes = RotationAxes.MouseXAndY;
 
 -         public float sensitivityX = 2F;
 
 -         public float sensitivityY = 2F;
 
  
-         public float minimumX = -180F;
 
 -         public float maximumX = 180F;
 
  
-         public float minimumY = -60F;
 
 -         public float maximumY = 60F;
 
  
-         float rotationY = 0F;
 
 -         void Update ()
 
 -         {        
 
 -                 if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved){
 
 -                         if (axes == RotationAxes.MouseXAndY)
 
 -                 {
 
 -                         float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
 
 -                         
 
 -                         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
 
 -                         rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
 
 -                         
 
 -                         transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
 
 -                 }
 
 -                 else if (axes == RotationAxes.MouseX)
 
 -                 {
 
 -                         transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
 
 -                 }
 
 -                 else
 
 -                 {
 
 -                         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
 
 -                         rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
 
 -                         
 
 -                         transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
 
 -                 }        
 
 -                 }
 
 -         }
 
  
-         void Start ()
 
 -         {
 
 -                 // Make the rigid body not change rotation
 
 -                 if (rigidbody)
 
 -                         rigidbody.freezeRotation = true;
 
 -         }
 
 - }
 
 
  复制代码 |   
 
 
 
 |