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
1
Question by dissidently · Mar 12, 2011 at 06:12 PM · iostouchdetectareaempty

iOS: how do I make an empty area a tappable target: Ring

I've made a 3D model of a ring and want the entire inside area of the ring, as well as it's frame, to register any taps inside or on the rim. Problem is, there's nothing in the center of the ring to do a raycast on, and no object for me to put a listener on for contact/touch in this middle/empty area of each ring. And that's the way I want it. I don't really want any more geometry or stuff flying around to deal with.

What's the most efficient way of solving this problem if there's a few of these rings on the screen at the same time and I want to differentiate between them; Some being the "right" ones to tap, some being the "wrong" ones.

Because I'm useless at explaining myself: Here's an image: so you know what I'm on about... http://imgur.com/1hJvh

And just image a half dozen of these floating around the screen.

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
2
Best Answer

Answer by AngryOldMan · Mar 17, 2011 at 02:06 PM

make the rings as prefabs with a collider on them (sphere or capsule only)with "is trigger" checked which reacts when "input.touches" is added in the script attached. This means you would have two prefabs that both looked the same but one had a script for "right" touch and one having a script for "wrong". Simple, no need for raycast this way :)

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 dissidently · Mar 18, 2011 at 01:46 AM 0
Share

which of these methods is the most processor efficient?

avatar image AngryOldMan · Mar 18, 2011 at 01:53 AM 0
Share

I think that the input.touch feature will be less processor intensive but I'm not 100% sure. I know it's simpler and less complex to implement. $$anonymous$$y general motto is less code less memory but that is, definatly, not always the case!

avatar image dissidently · Mar 18, 2011 at 06:05 AM 0
Share

wouldn't this mean that the number of objects I have onscreen equals the number of eventlisteners are operating? And that event listeners are processor drains in iOS? Whereas the ray approach only sends a ray on touch, and can use just one event listener, for the whole screen?

avatar image AngryOldMan · Mar 18, 2011 at 11:42 AM 0
Share

Like I said I wasn't 100% sure but the way you explain sounds right. But i don't think you need an event listener at all with input.touches?

avatar image
0

Answer by pyro 2 · Mar 17, 2011 at 02:03 PM

Add a SphereCollider to your ring, center it in the middle of the ring and adjust the radius so it envelopes the whole ring.

Then just use a a raycast from the camera to see if it is hitting one of your colliders.

function Update() { //check touches if (Input.touchCount > 0) { //grab touch var t = Input.touches[0];

     //check if it is the beginning of a touch
     if (t.phase == TouchPhase.Began)
     {
         //shoot a ray from the touch position into the scene
         var ray = Camera.main.ScreenPointToRay(t.position);
         var hit : RaycastHit;
         if (Physics.Raycast(ray, hit)) //check if the ray is hitting something
         {
             //destroy whatever was touched (modify this to your own gamelogic)
             Destroy(hit.transform.gameObject);
         }   
     }
 }

}

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

No one has followed this question yet.

Related Questions

Unresponsive Touch 0 Answers

iOS :: increase slider thumb touch area 1 Answer

Multitouch Area 1 Answer

Help With Touch to Drag Script 1 Answer

iOS touch recognition on UI has odd delays 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