Question by 
               Aziz1989 · Nov 09, 2015 at 04:00 PM · 
                c#mobiletouch controlscamerascamera viewport  
              
 
              Detect touch gesture in a more than one camera screen rendering
Hi,
I am developing a mobile application using two cameras.
I've attached the same code (below) to both of them and changed the output text for each.
I deleted any tags on them, put them in the same depth, but still get the output of one of them where ever i swipe.
I want the code to distinguish between those two zones (although they are two different FOV, i don't understand why it is not normally detected ).

PS: i am not using Ray-casting.
Thank you and this is my code :
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class DetectSwipeCam2 : MonoBehaviour
 {
     public GameObject Notification;
     private const int mMessageWidth = 200;
     private const int mMessageHeight = 64;
     
     private readonly Vector2 mXAxis = new Vector2 (1, 0);
     private readonly Vector2 mYAxis = new Vector2 (0, 1);
     
     private readonly string[] mMessage = {
         "",
         "Swipe Left CamNav",
         "Swipe Right CamNav",
         "Swipe Top CamNav",
         "Swipe Bottom CamNav"
     };
     
     private int mMessageIndex = 0;
     
     // The angle range for detecting swipe
     private const float mAngleRange = 30;
     
     // To recognize as swipe user should at lease swipe for this many pixels
     private const float mMinSwipeDist = 10.0f;
     
     // To recognize as a swipe the velocity of the swipe
     // should be at least mMinVelocity
     // Reduce or increase to control the swipe speed
     private const float mMinVelocity = 50.0f;
     
     private Vector2 mStartPosition;
     private float mSwipeStartTime;
     
     
     
     
     // Use this for initialization
     void Start ()
     {
         
     }
     
     // Update is called once per frame
     void Update ()
     {
         
         // Mouse button down, possible chance for a swipe
         if (Input.GetMouseButtonDown (0)) {
             // Record start time and position
             mStartPosition = new Vector2 (Input.mousePosition.x,
                                           Input.mousePosition.y);
             mSwipeStartTime = Time.time;
         }
         
         // Mouse button up, possible chance for a swipe
         if (Input.GetMouseButtonUp (0)) {
             float deltaTime = Time.time - mSwipeStartTime;
             
             Vector2 endPosition = new Vector2 (Input.mousePosition.x,
                                                Input.mousePosition.y);
             Vector2 swipeVector = endPosition - mStartPosition;
             
             float velocity = swipeVector.magnitude / deltaTime;
             
             if (velocity > mMinVelocity &&
                 swipeVector.magnitude > mMinSwipeDist) {
                 // if the swipe has enough velocity and enough distance
                 
                 swipeVector.Normalize ();
                 
                 float angleOfSwipe = Vector2.Dot (swipeVector, mXAxis);
                 angleOfSwipe = Mathf.Acos (angleOfSwipe) * Mathf.Rad2Deg;
                 
                 // Detect left and right swipe
             //if (mStartPosition.x = )
                 if (angleOfSwipe < mAngleRange) {
                     OnSwipeRight ();
                 } else if ((180.0f - angleOfSwipe) < mAngleRange) {
                     OnSwipeLeft ();
                 } else {
                     // Detect top and bottom swipe
                     angleOfSwipe = Vector2.Dot (swipeVector, mYAxis);
                     angleOfSwipe = Mathf.Acos (angleOfSwipe) * Mathf.Rad2Deg;
                     if (angleOfSwipe < mAngleRange) {
                         OnSwipeTop ();
                     } else if ((180.0f - angleOfSwipe) < mAngleRange) {
                         OnSwipeBottom ();
                     } else {
                         mMessageIndex = 0;
                     }
                     
                 }
             }
         }
     }
     
     //    void OnGUI ()
     //    {
     //        // Display the appropriate message
     //        GUI.Label (new Rect ((Screen.width - mMessageWidth) / 2,
     //                           (Screen.height - mMessageHeight) / 2,
     //                           mMessageWidth, mMessageHeight),
     //                  mMessage [mMessageIndex]);
     //    }
     
     private void OnSwipeLeft ()
     {if (this.tag == "MainCamera")
         { Notification.GetComponent<Text> ().text = "Swipe Left backg";
         Notification.GetComponent<Text> ().fontSize = 20;
         }
         else {
             Notification.GetComponent<Text>().text = "Swipe Left CamNav";
             Notification.GetComponent<Text>().fontSize = 20;
         }
         
         
     }
     
     private void OnSwipeRight ()
     {
         Notification.GetComponent<Text>().text = "Swipe Right CamNav";
         Notification.GetComponent<Text> ().fontSize = 20;
         
     }
     
     private void OnSwipeTop ()
     {
         Notification.GetComponent<Text> ().text ="Swipe Top CamNav";
         Notification.GetComponent<Text> ().fontSize = 20;
         
     }
     
     private void OnSwipeBottom ()
     {
         Notification.GetComponent<Text> ().text ="Swipe Bottom CamNav";
         Notification.GetComponent<Text> ().fontSize = 20;
         
     }
 }
 
               
                 
                two-cameras.jpg 
                (47.2 kB) 
               
 
              
               Comment
              
 
               
              Your answer