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 /
avatar image
0
Question by Ereptor · Jun 23, 2016 at 11:51 AM · androidraycastbuttontouchfocus

Button Focus Prevents Touch Raycast (Android C#)

I am working on Android and have the following touch-driven interactions in Update:

 void Update()
     {
         if (Input.touchCount == 1)
         {
             thisTouch = Input.GetTouch(0);
 
             if (thisTouch.phase == TouchPhase.Moved)
             {
                 if (Mathf.Abs(thisTouch.deltaPosition.y) > 16.0f || Mathf.Abs(thisTouch.deltaPosition.x) > 16.0f)
                 {
                     hasMovedThisTouch = true;
                 }
                 if (hasMovedThisTouch)
                 {
                     DoRotation(thisTouch.deltaPosition);
                 }
             }
             else if (thisTouch.phase == TouchPhase.Ended)
             {
                 if (!hasMovedThisTouch)
                 {
                     DoClick();
                 }
                 hasMovedThisTouch = false;
             }
         }
         else if (Input.touchCount == 2)
         {
             DoZoom(Input.GetTouch(0), Input.GetTouch(1));
             hasMovedThisTouch = true;
             if (Input.GetTouch(0).phase == TouchPhase.Ended && Input.GetTouch(1).phase == TouchPhase.Ended)
             {
                 hasMovedThisTouch = false;
             }
         }
         transform.LookAt(target);
     }

Which is basically: If one finger is touching and not moving, DoClick. If one finger is touching and moving, DoRotate. If two fingers are touching, DoZoom.

I also have a few buttons on my overlay canvas that affect objects in the scene. This causes a problem.

When I click a button, the next raycast is blocked. I believe that it is because an item in the GUI still has focus. I attempt to solve this by putting GUI.FocusControl(null); at the end of my Update, but this has no effect.

How do I keep my touch interactions prepared to raycast after a button has been pressed?

Comment
Add comment · Show 2
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
avatar image Ereptor · Jun 23, 2016 at 11:53 AM 0
Share

I suppose I should clarify about Raycast:

Raycast happens in DoClick. DoClick performs an action on the object you are clicking, which is deter$$anonymous$$ed by raycast.

avatar image Ereptor · Jun 23, 2016 at 01:37 PM 0
Share

These are the things I have tried that don't work:

Placing any of these in Update() does nothing:

 GUI.FocusControl(null);
 GUI.FocusControl("");
 GUI.UnfocusWindow();


I also made a function I put at the end of every button interaction. It does nothing:

 void RefreshGUI()
 {
     GUI.SetActive(false);
     GUI.SetActive(true);
 }

In all cases, the next non-button touch will not DoClick().

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Ereptor · Jun 23, 2016 at 02:32 PM

This problem was solved by pulling EventSystem.current.IsPointerOverGameObject(); out of DoClick().

DoClick() must be called from TouchPhase.Ended, but IsPointerOverGameObject() must be called from TouchPhase.Began.

I just had to store an "isClickingButton" bool in my active touch so it could be accessed in both phases.

Also, IsPointerOverGameObject required (thisTouch.fingerID); to work properly.

Comment
Add comment · Share
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

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

100 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 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 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

How to touch select 3D objects 2 Answers

Android 3D Touch for Menu 0 Answers

I am making android fps and my raycast shooting button don't work. What I should do? 1 Answer

How to make this buttons for Android? 1 Answer

Unity UI: neglect transparent area of button and trigger user input underneath it. 2 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