2016-07-21 5 views
0

タッチ入力用にTransform.RotateAroundスクリプトを変更します。 "Input.GetAxis"を取り除くと、カメラはターゲットの周りで独自に回転します。私はこれで使用する文字列へのタッチの位置を取得するためにコードをどのようにフォーマットするかを理解できないようです。もし誰かが素晴らしいだろうヒントを持っている!ここでUnity C#タッチでTransform.RotateAroundを使用して、ターゲットを中心にカメラを移動します。

は、コードは次のとおりです。

using UnityEngine; 
using System.Collections; 

[AddComponentMenu("Camera-Control/Mouse Orbit with zoom2")] 
public class MouseOrbitImproved2 : MonoBehaviour { 

public float speed; 
public Transform target; 
public float rotateSpeed; 
public Transform camera = Camera.main.transform; 
public Vector3 camPosition; 
public float camSpeed; 
public float minDistance; 
public float maxDistance; 
//private Vector3 moveDirection = Vector3.zero; 
//private Vector3 moveDirection = target.position; 
public float perspectiveZoomSpeed = 0.5f;  // The rate of change  of the field of view in perspective mode. 
public float orthoZoomSpeed = 0.5f;  // The rate of change of the orthographic size in orthographic mode. 

void start() { 

    //camPosition = camera.transform.position; 
} 

public void Update() { 
    if (Input.touchCount == 1) { 
     transform.LookAt(target); 
     Touch touchSwipe = Input.GetTouch(0); 
     string position = touchSwipe.deltaPosition; 

     transform.RotateAround(target.position, Vector3.up, Input.GetAxis(position)* speed); 
     transform.RotateAround(target.position, Vector3.forward, Input.GetAxis(position)* speed); 
    } 

     transform.LookAt(target); 
    /* 
     float scroll = Input.GetAxis("Mouse ScrollWheel"); 
     if (scroll != 0) 
     { 
      // calculate new position first... 
      camPosition += transform.forward * scroll * camSpeed; 
      // then compare to the limits: 
      float distanceToTarget = Vector3.Distance(target.position, camPosition); 
      // you can clamp the movement to min and max distances: 
      if (distanceToTarget > maxDistance){ // clamp at maxDistance... 
       camPosition = target.position - maxDistance * transform.forward; 
      } 
      if (distanceToTarget < minDistance){ // or at minDistance 
       camPosition = target.position - minDistance * transform.forward; 
      } 
      // finally, update the actual camera position: 
      transform.position = camPosition; 
     // set camera position 
     } 
     */ 

    // If there are two touches on the device... 
    if (Input.touchCount == 2) 
    { 
     // Store both touches. 
     Touch touchZero = Input.GetTouch(0); 
     Touch touchOne = Input.GetTouch(1); 

     // Find the position in the previous frame of each touch. 
     Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; 
     Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; 

     // Find the magnitude of the vector (the distance) between the touches in each frame. 
     float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; 
     float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; 

     // Find the difference in the distances between each frame. 
     float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; 

     // If the camera is orthographic... 
     if (Camera.main.orthographic) 
     { 
      // ... change the orthographic size based on the change in distance between the touches. 
      Camera.main.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed; 

      // Make sure the orthographic size never drops below zero. 
      Camera.main.orthographicSize = Mathf.Max(Camera.main.orthographicSize, 0.1f); 
     } 
     else 
     { 
      // Otherwise change the field of view based on the change in distance between the touches. 
      Camera.main.fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed; 

      // Clamp the field of view to make sure it's between 0 and 180. 
      Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, 0.1f, 179.9f); 
     } 


     } 
} 

public void ChangeToAxial(){ 
    Camera.main.transform.position = new Vector3 (45.3f,234.5f,66.9f); 
} 

public void ChangeToSagright(){ 
    Camera.main.transform.position = new Vector3 (28.13f,76.41f,222.68f); 
} 

public void ChangeToSagleft(){ 
    Camera.main.transform.position = new Vector3 (49.36f,66.85f,-93.78f); 
} 

public void ChangeToCoronal() { 
    Camera.main.transform.position = new Vector3 (-71.6f,69.66f,66.29f); 
} 

}

答えて

0

私はこの質問を見て、統一フォーラムUnit 5 forum rotating camera with touchから答えるならば、それは最高のかもしれないと思います。それはInput.GetAxisの代わりにInput.GetTouchで動作するはずです。希望が役立ちます。スクリプトはJavascriptであることに注意してください。ただし、スクリプト全体は必要ありません。

+0

ありがとうございました! – jrogers12

関連する問題