Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by digitaldan · Jan 05, 2018 at 10:00 PM · spritetoucherror messagetouch controlsmobile devices

Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices

Hello, I wrote this custom script in order to enable my mobile application to use touch controls on a sprite and navigate to a next scene or page. The code I wrote below is uses a isTouched function to call the LoadScene method inside so that when I load my application, I can tap on the screen and it will load the next scene.

public class Next_lvl : MonoBehaviour {

 public static Collider2D cd;

 void Update () {
     if (isTouched ()) {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
     }
 }

 public bool isTouched(){
     bool result = false;
     if (Input.touchCount == 1) {
         if (Input.touches [0].phase == TouchPhase.Ended) {
             Vector3 wp = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position);
             Vector2 touchPos = new Vector2 (wp.x, wp.y);
             if (cd == Physics2D.OverlapPoint (touchPos)) {
                 result = true;
             }
         }
     }
     return result;
 }

}

However, this causes my application to have bugs in it, crashes and does allow me to navigate to any other pages when I test this on the phone. I keep getting this error that game scripts or other custom code contains OnMouse_ event handlers. The presence of such handlers might impact performance on handheld devices. I'm not sure why my code generates this error but is there anyway I can write a touch method that would allow me to tap on a sprite on my mobile device the go to another scene or call a function without causing errors on my phone.

Thank you.

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

2 Replies

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

Answer by Lysander · Jan 05, 2018 at 11:13 PM

Looks fine, and none of this shows any OnMouse_ events (such as OnMouseEnter, OnMouseExit, etc...), so it's probably referring to a different script. I would suggest a couple of things though- use a button instead of a Collider2D, as that's what they're made for. If you need non-rectangular buttons, just set this setting higher than 0 on the Image component the button is attached to.

Also, the use of scenes for something like "pages" may be inefficient (if that's like a "turning pages in a book" kind of situation)- possibly far more inefficient than any specific input methods on mobile. I would recommend looking into statemachines in a single scene, and enable and disable GameObjects as the state changes, if you have the memory for it.

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 digitaldan · Jan 09, 2018 at 05:38 PM 0
Share

Would you say creating a Save State and a Load State are the best ways of saving and loading the scenes in my application.

avatar image
0

Answer by Kheremos · Feb 22 at 04:50 PM

Great answer above, but link has changed: https://docs.unity3d.com/ScriptReference/UI.Image-alphaHitTestMinimumThreshold.html One reference for the above broken link is: https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.Image-alphaHitTestMinimumThreshold.html

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

169 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

Related Questions

How to get the touch controls to work smooth and properly in FPS android gamemobile Game? 1 Answer

Rotate GameObject on Touch along Y axis 1 Answer

How to replace KeyCode.Space with a simple tap on Android? 1 Answer

Addforce to Z axis rotation via touch input/ mobile 0 Answers

iOS touch delay? 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