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 hyruleoflink · Sep 14, 2015 at 06:15 AM · androidunity5touchonmousedown

Problem with touch detection

Hi.

I'm using the function OnMouseDown() to detect when the object has been touched and destroy it, My code is:

 void OnMouseDown(){
         GetComponent<AudioSource> ().Play ();
         NotificationCenter.DefaultCenter().PostNotification(this, "addScore", myPoints);
         Invoke ("destroyBall", 0.1f);
     }
     
     void destroyBall(){
         Destroy (this.gameObject);
     }

The code works in the computer, but when I test it in my phone, sometimes works, and sometimes doesn't work. I test in anothers devices and it's the same.

Any idea?

Comment
Add comment · Show 4
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 hexagonius · Sep 14, 2015 at 06:19 AM 0
Share

please be more precise on what does not work.

if the clip you're playing is .1f seconds long, this code is fine, but you should replace the invoke delay by

 GetComponent<AudioSource> ().clip.Lenght
avatar image hyruleoflink hexagonius · Sep 14, 2015 at 06:26 AM 0
Share

Thanks, I try it.

avatar image Rostam24 · Sep 14, 2015 at 09:16 AM 0
Share

Test in which cases it does not work. For instance, maybe it works with a single touch, but multi-touch gives errors..?

avatar image hyruleoflink Rostam24 · Sep 14, 2015 at 10:06 AM 0
Share

I tested the game with only single touches, but still happens... $$anonymous$$aybe the problem is the detection of the collision, but I don't know how improve it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hyruleoflink · Sep 16, 2015 at 09:51 AM

I finally solved the problem. The cause was the Unity's physics engine. I used the gravity to move the object, but If I use the variable "velocity" fron Rigidbody2D, the game works well.

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

31 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

Related Questions

Tetris grid 1 Answer

How can I detect touch on a Mesh Collider on an Android device ? 3 Answers

Create an array of touches in Android? 0 Answers

Why are my tilt controls are replaced by touch? 1 Answer

TCP messages can be received over localhost (in windows and editor) and to testing app on android device over local network, but not with a Unity built android app. 3 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