Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 MrWy07 · Aug 10, 2021 at 08:05 AM · mobiletouchtaptouchphase

Taps are not detected on mobile

This is strange. When I test my game in Unity remote this code works just fine (although the buttons, which have an Event Trigger component attached, don't), but when I build it, it seems like no taps are detected (and the buttons work fine!). So, does anybody know why my taps are not detected on my phone (only on the built version)?

 public class RotateChY : MonoBehaviour{
     bool menuEnabled = true;
     bool tapping = false;
     
         [SerializeField] float rotationSpeed = 1f;
     
         [SerializeField] GameObject chHolder;
         [SerializeField] GameObject chSelectionScreen;
         
         private void Start() {
             chHolder.SetActive(true);
             chSelectionScreen.SetActive(false);
         }
     
         private void Update() {
                 if(Input.touchCount > 0) {
                     Touch screenTouch = Input.GetTouch(0);
     
                     if(screenTouch.phase == TouchPhase.Moved) {
                         menuEnabled = false;
                         transform.Rotate(0, -screenTouch.deltaPosition.x * Time.deltaTime * rotationSpeed, 0);
                         } 
                         else if(screenTouch.phase == TouchPhase.Ended) {
                         if(menuEnabled) {
                             openChSelectScreen(true);
                         } else {
                             menuEnabled = true;
                         }
                     }
                 }
         }
     
         public void openChSelectScreen(bool val) {
             chHolder.SetActive(!val);
             chSelectionScreen.SetActive(val);
         }
     }

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

1 Reply

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

Answer by Mehmedcan · Aug 11, 2021 at 08:59 AM

@MrWy07 Input.touchCount() function not working for mobile. When Unity Remote application is used, the part that appears on the phone is actually compiled by the computer.

You can use:

 Input.GetMouseButtonDown(0)       // Returns true when user pressed the screen
 Input.GetMouseButtonUp(0)         // Returns true when user releases the screen
 Input.GetMouseButton(0)           // Returns true when user held down the screen
Comment
Add comment · Show 2 · 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
avatar image MrWy07 · Aug 11, 2021 at 09:30 AM 0
Share

InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.

I think tour answer is great but it seems like I need the equivalent ones for the new input system.

avatar image MrWy07 MrWy07 · Aug 13, 2021 at 09:16 AM 0
Share

Actually I found it easier to just change the input system to both and now it work perfectly with your functions, thank you ! <3

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

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

What's the right way to detect double tap on a phone? 0 Answers

Input.touchCount returning wrong number 0 Answers

What's the BEST: most efficient, reliable, cross-platform way to detect a touch/tap on mobile (Android-iOS) on several 2D colliders in a scene while still retaining desktop compatibility and raycast/touch masking? 0 Answers

My dragging script "Sucks" all the other objects when touching it 1 Answer

Unity2D move object by touch input 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