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 /
avatar image
0
Question by Intrawebs · Jun 01, 2011 at 06:45 PM · androidguiiosguitexturesphere

GUITexture with Sphere Collider

I have a GUITexture that I want to have it trigger its MouseDown event based not on touching the texture itself but instead a touch on a circle within the texture. The "touch" zone if you will is an actual circle that has a diameter 80% of the width of the texture (and centered in the textured), if it's full width then thats too sensitive of a touch zone for this particular game.

So, I looked into maybe using a SphereCollider but maybe there is a simpler way and also how to integrate it's trigger and events into something that is in the GUI in screen space coordinates. This will need to work on iOS and Android and web browser/unity (only browser/unity for testing etc).

I'm using the button script for Unity 3.x below which works great as is. Also, new to Unity but I've gone through the entire 3D Platformer tutorial, good stuff! http://www.unifycommunity.com/wiki/index.php?title=Button

Thanks to the responese the following worked for me.

         var touchDist = pos - new Vector2(radius,radius);    
         if (touchDist.magnitude <= (radius))
           Debug.Log("HIT SUCCESS " + pos);
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
1
Best Answer

Answer by Wolfram · Jun 01, 2011 at 11:42 PM

You could compute it directly according to your mouse position, instead of using some pseudo-3D collider functionality of Unity. I don't know the actual syntax, though, although I do know the functionality to accomplish the following is provided by Unity. Meaning, this is very raw pseudo-code, which nevertheless should point you in the right direction:

 if(UnityFunctionThatDetectsWhetherTheGUITextureHasBeenPushed()){
     touchDistanceVector=MousePositionXY()-CenterOfGuiTexture();
     if(touchDistanceVector.sqrMagnitude<(0.8*WidthOfGuiTexture)*(0.8*WidthOfGuiTexture)){
         print("GUITexture hit within 80% width circle!");
     }
 }  
Comment
Add comment · Show 2 · 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 Intrawebs · Jun 02, 2011 at 02:49 AM 0
Share

You guys both game the same answer for the most part but since you posted some sort of code I gave you the credit. $$anonymous$$an, it's much simpler than I thought, sometimes I'm just unable to break it down to the nuts and bolts without others eyes looking at the problem. Thanks @Wolfram and @DaveA.

avatar image Intrawebs · Jun 02, 2011 at 05:55 AM 0
Share

Im unable to edit my answer that I put in my question, it should not be "new Vector2(radius,radius);" but ins$$anonymous$$d "new Vector2(width/2,height/2);"

avatar image
1

Answer by DaveA · Jun 01, 2011 at 10:42 PM

SphereCollider sounds like overkill. In that script you linked to, there is a HitTest function. I think you'd modify that to look within the radius you desire to 'filter' out the click. In other words, the 'hot spot' is a rectangle enclosing your circle, and if it's hit, then look to see if it's hit within the radius (excluding the corners).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Store/Stack Items 0 Answers

Unity GUI with Android 2 Answers

Button as a child of a button 0 Answers

InputField - Stop unity from dismissing touch screen keyboard on outside click? 0 Answers

GUI Tutorial or free GUI Manager like EZ GUI and NGUI for Android and iOS 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