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 Dakwamine · Mar 30, 2012 at 05:47 PM · mouseguitextureviewportrectshift

OnMouse functions not working properly on GUITexture when changing viewport rect

When I change Normalized View Port Rect width or height of my main camera, the active area of mouse event functions like OnMouseEnter and OnMouseExit on GUITexture objects is not correctly placed over the image.

For example, if I reduce the width of the Normalized View Port Rect, the active area of my GUITexture is shifted to the left.

I do not want to use GUI scripts even if I know how to use them.

Example

Description

In the example Unity file from the link below, when I point the mouse cursor above the image, it should normally have its alpha color changed. But in this case, with a modified Normalized View Port Rect (width = 0.5), this only happens when I point at the left of the image.

Link

Here it is

Script

 #pragma strict
 
 function OnMouseEnter() {guiTexture.color.a = 0.1;}
 
 function OnMouseExit() {guiTexture.color.a = 1.0;}

Question

Is it a bug ? How can I workaround ?

Update log

[Update] Added on GUITexture objects in the first paragraph.

[Update 2] Added link to an example export.

[Update 3] Added script used + formatting the question.

Comment
Add comment · Show 1
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 Dakwamine · Mar 31, 2012 at 01:44 PM 0
Share

Is my question irrelevant?

1 Reply

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

Answer by aldonaletto · Apr 02, 2012 at 08:33 PM

Yes, this looks like a big fat bug! I tested this, and the "sensible" area moved down and left - even when the viewport was set to the upper right corner.
The 3 bastard sons of Unity are TextMesh, GUIText and GUITexture. Many things with them are weird: TextMesh Z axis points backwards, its shader renders over everything in the 3D world, GUIText and GUITexture use viewport coordinates in the position field, ignore rotation and have an undecipherable interpretation of scale, GUIText doesn't have a color property... there are many weird things, and this bug comes to make things worse.
If the sensible area of your texture may be simplified to a rectangle, you can define some sensible rectangles and use Rect.Contains(Input.mousePosition) to check when the mouse entered them:

var r1:Rect = Rect(10,10,200,100); var r2:Rect = Rect(300,10,200,100);

function Update(){ if (r1.Contains(Input.mousePosition)){ // mouse over r1 } else { // mouse out of r1 } if (r2.Contains(Input.mousePosition)){ // mouse over r2 } else { // mouse out of r2 } } The alternative is the new GUI system, which you seem to hate (I don't like it too...)

Comment
Add comment · Show 3 · 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 Dakwamine · Apr 03, 2012 at 03:03 PM 0
Share

Thanks for your reply!

The new GUI system is not that much bad, but despite its advantages, it takes more steps and time to design GUI elements than using the GUITexture / GUIText.

avatar image aldonaletto · Apr 03, 2012 at 09:24 PM 1
Share

Yes, and you can't see what you're doing without running the project. But the worst thing is when we forget to which script that damned thing was added...

avatar image Dakwamine · Dec 01, 2016 at 09:44 AM 0
Share

Why your answer was not accepted before is a mystery for me. Now it is fixed. ^^

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Detecting a mouse hover using an alpha channel not a rect 0 Answers

Blur script changes Viewport rect ? 0 Answers

Changing the Camera viewport rect results in resizing the objects rendered by the specific camera ? 1 Answer

Having Issues with Camera Viewport Rect 0 Answers

Rect, Texture, GUI, Detection. 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