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
0
Question by Travis 18 · Jan 31, 2011 at 05:41 PM · collideronmousedownaspect-ratio

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

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
0

Answer by JoshOClock · Jan 31, 2011 at 05:56 PM

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.

Comment
Add comment · Show 1 · 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 Travis 18 · Jan 31, 2011 at 06:08 PM 0
Share

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

avatar image
0

Answer by csciguy · Feb 24, 2012 at 09:22 PM

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.

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

1 Person is following this question.

avatar image

Related Questions

Want collider to detect mouse clicks but not player collision 1 Answer

how to not trigger two collaiders by one click 0 Answers

BoxCollider 2D not working OnMouseDown() 1 Answer

OnMouseDown() not called on child object collider 2 Answers

OnMouseDown() won't work unless gameObject's 2DBox Collider - ‘Is Trigger’ is toggled on/off mid-game in editor. 0 Answers


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