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.
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 :)
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);
}
}
}
}