Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 theroid · Apr 15, 2014 at 09:14 PM · androidraycasttouchmenu

Menu issues - selecting [BACK] closes app

I have 3 GameObjects ('menu screens', as groups of text, planes and box colliders) in the same world position, which are hidden and shown as needed (switching menus). Running the code within Unity (MouseButtonDown etc) produces the desired results (click PLAY, mainMenu closes, playMenu opens, click BACK in playMenu, playMenu closes, mainMenu opens etc), but running it on my Android produces a different result. Upon touching BACK in playMenu, the app closes as if Application.Quit() was called.

edit: I should mention that the BACK and QUIT buttons are in the same position in each menu.

Raycaster() is called from Update(). These are just the offending pieces of code, this reproduces the result every time. Both the mouse and touch inputs are there so I can check things a bit quicker than building to Android after editing.

As a side note, I have had my menu working just fine in the past, however I thought of a 'better' way to do it, and erased the entire script. Rookie mistake, my bad. I think I once had this working with dragged variables, I'm not sure if that is extra work (for me and/or the machine).

After all that, my question is twofold:

What is going on in my code to cause this bug? and...

Is this the best way to perform the desired action?

Code: (C#)

 void RayCaster() {
         if(Input.GetMouseButtonDown(0)) {
             touchRay = menuCamera.camera.ScreenPointToRay(Input.mousePosition);
             RayCastChecker();
         }
         if((Input.touchCount > 0) && (Input.GetTouch (0).phase == TouchPhase.Began)) {
             touchRay = menuCamera.camera.ScreenPointToRay(Input.mousePosition);
             RayCastChecker();
         }
     }
 
     void RayCastChecker() {
         if(Physics.Raycast(touchRay, out touchRayHit, 20)) {
             if(touchRayHit.collider.gameObject.name == "MainButton1") {
                 mainMenu.SetActive(false);
                 playMenu.SetActive (true);
             }
             if(touchRayHit.collider.gameObject.name == "PlayButton3") {
                 mainMenu.SetActive(true);
                 playMenu.SetActive(false);
             }
             if(touchRayHit.collider.gameObject.name == "MainButton3") {
                 Application.Quit();
             }
 
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 theroid · Apr 16, 2014 at 06:40 AM

After sleeping on it, it would appear that touches are treated as mouse clicks, so I was calling the process twice in a frame, resulting in two touches/clicks being registered before the frame could draw. Removing either input reference fixes the problem. I should have picked this up earlier (mousePosition being a major clue).

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

20 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

Related Questions

Button Focus Prevents Touch Raycast (Android C#) 1 Answer

How to make a android touch menu? 0 Answers

Touch to move 3 Answers

Android Touch Cube on screen , level To Load 1 Answer

raycasting and layermask question 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