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 rhbrr5hrfgdfgw · Jun 17, 2015 at 03:21 AM · androidjavascriptgui

Tap anywhere and buttons (android)

I am making a game and i want that in the main menu whenever the player touchs the screen the game would start.(the pass to start the game works) the only problem is that i have another buttons in the screen(like mute button or button to get into the store) and when i click them nothing happens because its passing the player to the game.

          if (GUI.Button(Rect(0 ,0 ,100 ,100),"" , muteButton)){//Mute button
  //Code to mute
              }
          if(Input.GetMouseButtonUp(0)){//TapAnywhere
  //Start the game
          }

I tried it with else if and its still doesn't work.(And all the code is in GUI Function)

Comment
Add comment · Show 2
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 revolute · Jun 17, 2015 at 04:49 AM 0
Share

Do you simply want touch? Input.anykey for editor and Input.touchCount works if that is what you want.

avatar image rhbrr5hrfgdfgw · Jun 17, 2015 at 04:42 PM 0
Share

You dont understand me, the tap anywhere already works, but if i have a button in the screen then its blocking it.

1 Reply

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

Answer by smallbit · Jun 17, 2015 at 05:03 AM

You either make sure that the mouse click position (REF happens in the area without button (i.e. bottom 80% of the screen) or even simpler create a very big invisible button which will start the game. For that you will need to drop using old GUI.button and use some more evolved solution like Unity UI (version 4.6 upwards) or NGUI. In that way you can adjust collider to not overlap with other buttons. If you really need the area to touch to start the game to be anywhere even between your other buttons, than set this button depth to lower (so its below the other buttons), that would work with NGUI not sure about unity canvas. If you however want to stick to use basic GUI.buttons track mouse click position and only start the game when is not overlapping the screen. In practice this area dont need to cover entire screen just big chunk of the middle.

Comment
Add comment · Show 4 · 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 rhbrr5hrfgdfgw · Jun 17, 2015 at 04:43 PM 0
Share

Is Input.mousePosition gives me the exact x and y just like where i place it in the Rect( , , ,)?

avatar image smallbit · Jun 18, 2015 at 08:18 AM 0
Share

You need to test it out ? use debug.log(Input.mousePosition) in Update to see what it gives you. I think it goes from 0,0 (left bottom corner) to screen.width,screen.height top right corner. so in your case if you want the bottom 70% of the screen you would do something like :

  if(Input.Get$$anonymous$$ouseButtonUp(0) && Input.mousePosition.y < Screen.height*0.7f)
 
 {//Tap on the bottom 70% of the screen 
   //Start the game
           }

but than again just test it out

avatar image rhbrr5hrfgdfgw · Jun 18, 2015 at 03:33 PM 0
Share

Actually i already fixed it, thank you for your help. What i did is: I checked if theres a button click and if the click is not in the button bounds(for example the mute button Rect is (0,0,100,100) so: if(Input.Get$$anonymous$$ouseButtonUp(0) && Input.mousePosition.x > 100 && Input.mousePosition.y > 100){ //Start game

avatar image smallbit · Jun 19, 2015 at 05:14 AM 0
Share

You should definitely check your solution on different resolutions, since you use absolute values it will work, thus on big screens (i.e. retina) your buttons will be very small. Thus you should adapt button size and the mouse click code in relation to screen width and heigth

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

display txt file content on textarea GUI Android 1 Answer

Android touch gui help!!! 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Android Options Menu 0 Answers

Saving items to a text file 1 Answer


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