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 Der-Die-Das · Feb 26, 2018 at 07:07 AM · androidbuildtouchandroid buildtouch controls

Android Touch Input not working in Build

I've seen a question like this one multiple times but it never got answered to work for me. So, I've worked with Touch Input in the past but this is my first time working with Touch Input in Unity 2017. Below is my Code. This Code works when I play the Game and test it via Unity Remote, but not in the Build. Does anyone have a Idea? I tried so many things. :(

  if (Input.GetMouseButtonDown(0))
  {
      Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
      RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero);
      if (hit.collider != null)
      {
          MapTile tile = hit.transform.GetComponent<MapTile>();
          if (tile != null)
          {
              entityMovement.MoveOffset(tile.Position - Position);
              ShowWalkableTiles();
              gameManager.PlayerDidTurn();
              return;
          }
      }
  }
  /*else*/
  if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Ended)
  {
      Debug.Log("Touch");
      Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
      RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero);
      if (hit.collider != null)
      {
          MapTile tile = hit.transform.GetComponent<MapTile>();
          if (tile != null)
          {
              entityMovement.MoveOffset(tile.Position - Position);
              ShowWalkableTiles();
              gameManager.PlayerDidTurn();
              return;
          }
      }
  }
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

3 Replies

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

Answer by Der-Die-Das · Feb 27, 2018 at 11:28 AM

It finaly worked by just using Input.touches[0] instead of Input.GetTouch(0). No clue why though.

Comment
Add comment · Show 3 · 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 Bunny83 · May 06, 2018 at 12:15 PM 0
Share

I just stumbled across this question.


Sorry but this answer makes no sense. The touches property of the Input class is just:

 public static Touch[] touches
 {
     get
     {
         int count = touchCount;
         Touch[] touches = new Touch[count];
         for (int q = 0; q < count; ++q)
             touches[q] = GetTouch(q);
         return touches;
     }
 }

So you effectively are just calling GetTouch(0) but in a more expensive way.


avatar image Der-Die-Das Bunny83 · May 06, 2018 at 12:18 PM 0
Share

Yeah, I know it doesn't make any sense.. But it worked in the end. I'm sorry for anyone who has the same problem but this doesn't solve it.

avatar image shayCohen007 · Mar 30, 2020 at 12:30 PM 0
Share

hey, i think have the same problem that you had, but i didn't understand the solution... I created an Android app. When I build it to 32 bit it works fine but when I build it to 64 bit the touch does not work. I tried to change all kinds of functions but once I install the app on my phone the touch does not work.

Please help me, I've built a lot of apps and it never happened to me

this is my code:

void Update() {

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit;

if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) if (Physics.Raycast(ray, out hit, $$anonymous$$athf.Infinity)) { Debug.Log(hit.transform.gameObject.name);

if (hit.transform.gameObject.name == this.name) {

if (OnBlockPressed != null) {

OnBlockPressed(this);

}

}

} } }

avatar image
0

Answer by Luisoft · Feb 26, 2018 at 10:39 AM

Try using touches instead of mouse clicks on your Android device.


Touch firstTouch = Input.GetTouch(0);
if (firstTouch.phase == TouchPhase.Began)
{
  // The touch started this is equal to a MouseDown
}

Keep in mind you should have a class to abstract your Input code from your logic.

Comment
Add comment · Show 1 · 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 Der-Die-Das · Feb 26, 2018 at 12:51 PM 0
Share

I did pretty much the same thing, didn't I? I just used TouchPhase.Ended ins$$anonymous$$d.

But yeah. I will seperate Input from Logic. Thanks

avatar image
0

Answer by guilhermern · Feb 26, 2018 at 11:58 AM

Mouse simulation with touches can be enabled/disabled with Input.simulateMouseWithTouches option. By default this option is enabled.

Comment
Add comment · Show 1 · 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 Der-Die-Das · Feb 26, 2018 at 12:51 PM 0
Share

I tried enabling it. Didn't work. I may try to disable it. Thanks

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

192 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

Related Questions

I am having trouble building the project for android 0 Answers

Remove IPostGenerateGradleAndroidProject callback at build time 0 Answers

Gradle build: Could not compile build.gradle error 1 Answer

Android build error 1 Answer

Failed Running UnityLinker.exe and UnityLinker.exe did not run properly! 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