x


How to get 'object touched' (Non-GUI) on iPhone?

Please forgive if asked/answered, so many posts!

I have some in-scene (NOT GUI!) objects I need to know if the user touches (clicks).

In my Win/Mac version I have a collider on my object which repsonds to OnMouseDown

What's the equivalent for iPhone, if any? I've seen the GUI solutions, not what I need.

more ▼

asked Sep 01 '10 at 09:55 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

Is this question different to http://answers.unity3d.com/questions/5941/is-it-possible-to-touch-3d-object-for-using-unity-in-iphone ? It might well be - I'm unfamiliar with Unity iPhone - but it shows up as the top of the related question list, and sounds similar!

Sep 02 '10 at 04:01 AM Marowi
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I wanted this to be a 'drop in' replacement for my mousehandler, so here's the script I put on my prefab:

function Update() {

if (Input.GetMouseButtonDown(0)) // check for left-mouse
{
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
    if (collider && collider.Raycast (ray, hit, 100.0))
    {
        OnMouseDown();
    }
}

}

function OnMouseDown() { blah blah }

more ▼

answered Sep 02 '10 at 03:54 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left

var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;

if (Physics.Raycast (ray, hit, 200)) 
{
    var objecthit:Transform = hit.transform as Transform;

    // What are you hitting?
    if (hit.collider.tag == "3DButton") doStuff()
     }
more ▼

answered Sep 01 '10 at 11:17 PM

jtbentley gravatar image

jtbentley
579 3 4 16

Pretty close, thanks

Sep 02 '10 at 03:50 AM DaveA
(comments are locked)
10|3000 characters needed characters left

You can also use OnMouseDown(), which is easier, but the object has to have a collider, I believe.

more ▼

answered Sep 02 '10 at 01:36 AM

qJake gravatar image

qJake
11.6k 43 78 161

No, not available on iPhone (2.6)

Sep 02 '10 at 03:50 AM DaveA

Are you sure? I've used OnMouseDown() on Android... perhaps it's a 3.0-only feature.

Sep 02 '10 at 07:53 AM qJake

That may be. I'm not using 3.0 'seriously' yet as so many things are broken for me.

Sep 04 '10 at 01:06 AM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2001
x985
x583
x225

asked: Sep 01 '10 at 09:55 PM

Seen: 4699 times

Last Updated: Jan 15 '12 at 05:30 PM