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 TheMorten · May 18, 2010 at 12:13 PM · cameraguiviewport

Detecting camera viewport on mouse down?

Hey,

I'm trying to do a chat interface with a camera viewport that takes up only a part of the entire screen. The rest of the screen space is used for chat boxes and other interface stuff.

The user should be able to rotate the camera around the playing area, which is displayed in the camera viewport, somewhat akin to Homeworld or WoW style controls. When the user presses the right mouse button, I want to find out if the mouse pointer is inside the viewport or not. If it is not, nothing should happen (not even if the mouse is moved into the viewport after clicking). If the mouse pointer is over the viewport and the right mouse button is clicked and held down, the camera should rotate around an arbitrary focus point (conveniently named the "character" in my project), based on mouse movement.

I'm figuring out how to do camera rotation and such by looking at other scripts, so answers need not include that (although a really simple script suggestion would of course be nice :) ), but I have no idea how to check whether the mouse pointer is inside the viewport.

Ideally, buttons occluding the camera viewport should also prevent the camera controls from becoming active if the mouse pointer is pointing at them.

I would like to post some coding examples, but what I have is not my programming (I don't fully grasp it and it is miles long), and as for the mouse check I haven't been able to write a single line yet - I simply don't know how to get started. :(

Thanks in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by StephanK · May 18, 2010 at 03:37 PM

You can get a cameras normalized viewport with camera.pixelRect This will give you the area of the screen that this camera renders to. All you need to do is find out if Input.mousePosition is inside that rectangle. You can use this:

if (Input.GetButtonDown("Fire1") && Camera.main.pixelRect.Contains(Input.mousePosition))
  DoSomething();

Not tested, but this should give you an idea.

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 TheMorten · May 18, 2010 at 07:44 PM 0
Share

Worked like a charm, thanks a bunch!

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

Camera Viewport Shape 0 Answers

Can the Camera be Positioned on the Game Screen through code? 0 Answers

Hide GUI if it's out of camera Viewport? 1 Answer

what concept is used here ? 1 Answer

Camera picture stretching when width changed in script? 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