Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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 ).

alt text

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot Jump while moving, using Touch Controls for Android 1 Answer

How do you move 3D object by touch on mobile 0 Answers

How to get the touch controls to work properly? 0 Answers

How to separate a Tap from a Swipe? 0 Answers

ScreenToWorldPoint on One Axis? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges