Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by rhose87 · Oct 21, 2011 at 04:01 PM · cameraguimousecamera-movementorbit

Rotating object with GUI Elements present

I have a house that has a rotate script attached. I also have 2 gui texture above the house and a color picker that appears whel one of the above buttons are selected. i want to disable the rotate function if the mouse is over any of the gui elements.

Image

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

3 Replies

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

Answer by jahroy · Oct 21, 2011 at 05:00 PM

We do this by writing a function in the GUI script that returns a boolean indicating whether or not orbit input should be ignored. This function is easy to write: it gets the mouse position and checks whether or not it is inside the rectangle of any of our GUI controls (using Rect.Contains).

The camera control script calls this function at the beginning of its Update function. If guiController.isCameraInputIgnored() returns true, the Update function is exitted without processing any input.

The easiest way to get the scripts to play together is to declare an object in your camera control script that is of the same type as your GUI script.

In other words, if your GUI script is in a file named MyAwesomeGUI.js you would add the following to your camera script:

/* declare a variable that represents your gui script */

var guiController : MyAwesomeGUI;

function Update () { / only do this if the guiController var has been assigned /

 if ( guiController != null ) {

     if ( guiController.isCameraInputIgnored() ) {
         return;
     }
 }

 /* add orbit code here */

}

I'm sure there are a trillion other ways to do it....

Just to be thorough, here's a simple example of a function named isCameraInputIgnored in a sample script:

/* example implementation of MyAwesomeGUI.js */

var playButtonRect : Rect = Rect(0, 0, 100, 40); var quitButtonRect : Rect = Rect(0, 40, 100, 40);

/ return true if orbit input should be ignored /

function isCameraInputIgnored () : boolean { var mousePos : Vector3 = Input.mousePosition;

 /* invert the y-coordinate */

 mousePos.y = Screen.height - mousePos.y;

 if ( playButtonRect.Contains(mousePos) ) {
     return true;
 }

 if ( quitButtonRect.Contains(mousePos) ) {
     return true;
 }

 return false;

}

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
avatar image
0

Answer by rhose87 · Oct 21, 2011 at 05:33 PM

i will try this on monday and come back with the result. thanks in advance.

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 jahroy · Oct 21, 2011 at 05:43 PM 2
Share

You're welcome. Let me know if you have any questions.

By the way... Comments like this should not be added as new answers. They should be added to other answers as comments (like I'm doing now). To add a comment, click "add new comment" under an answer.

You should only create a new answer if you're offering a new and different way to solve the current question.

This allows other users to get the most out of this amazing website.

avatar image
0

Answer by rhose87 · Oct 24, 2011 at 07:56 AM

Mouse Orbit is the script behind the camera and tilesButtonClick is the script behind all my 7 buttons. i've added : var guiController : tilesButtonClick; to my MouseOrbit.js isCameraInputIgnored () function to tilesButtonClick.js but i get an error : "The name "tilesButtonClick" does not denote a valid type." ideas ?

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 timsk · Oct 24, 2011 at 11:59 AM 0
Share

got it. sorry (2 days ago)

You don't got it.

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

Touch mouseorbit 5 Answers

How to set horizon level for camera orbit script? 0 Answers

Camera Orbit on Left Click problem 0 Answers

Mouse Orbit snapping issues 0 Answers

Control the scene camera using arrow gui buttons 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