x


Why does OnMouseDown work in Free Aspect, but NOT in 1024 x 768?

In my project (a Windows Streaming Web Player app), I have an object that instantiates, along with a script that allows the user to click on it to move it around and so forth. The instantiated object has a OnMouseDown() function call to perform all the stuff its supposed to do.

The problem is when the aspect ratio is set to Free Aspect, I have no problem clicking on the object. But when it's in Standalone (1024 x 768), which is the resolution I need, I can't click the object. I've used Debug.Log calls to confirm that in Free Aspect it's registering OnMouseDown clicks, and in Standalone it isn't.

The collision box is the same in both aspects, so it's not the collider's fault, I think.

The code couldn't be simpler:

void OnMouseDown ( )
{
    Debug.Log ( "Clicked!");
}

What's happening here? What's the relationship between Aspect Ratio and colliders in the OnMouseDown() function?

Thanks

more ▼

asked Jan 31 '11 at 05:41 PM

Travis 18 gravatar image

Travis 18
16 1 1 1

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

2 answers: sort oldest

I haven't tried to replicate your situation. But personally I use this c# code in my game:

if (Input.GetButtonDown("Fire1"))
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    RaycastHit hit;
    if (Physics.Raycast(ray, out hit, 100))
    {
        //....
    }
}

And it's been working on PC/Mac/Web/Android and iOS in all resolutions, for button clicks and touches on the screen.

You probably want this in some singleton class called "Input" or something so you don't call it for every object in the game. Call it from some main object and then call some method on the object you clicked on.

more ▼

answered Jan 31 '11 at 05:56 PM

JoshOClock gravatar image

JoshOClock
227 14 14 23

Yeah, that's my planned workaround. Glad to know it's a viable solution.

Jan 31 '11 at 06:08 PM Travis 18
(comments are locked)
10|3000 characters needed characters left

I'm having this exact same issue. My colliders work all day in Free Aspect. The minute I make a build at 1024x768, they stop working however. I've used the same methodology/code to handle OnMouseDown events for years now. Short of writing my own raycasting, did you ever find a workaround?,I'm having this exact same issue with some colliders in my scene. They work fine in free aspect, but not in standalone.

more ▼

answered Feb 24 '12 at 09:22 PM

csciguy gravatar image

csciguy
59 3 3 4

(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:

x1703
x120
x43

asked: Jan 31 '11 at 05:41 PM

Seen: 1450 times

Last Updated: Feb 24 '12 at 09:35 PM