- Home /
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.
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;
}
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.
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.
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 ?
Your answer
Follow this Question
Related Questions
Camera Movement issue 1 Answer
Use mouse to move camera along fixed axis through city scene 0 Answers
Camera Orbit with multiple Cameras in scene 1 Answer
Need help with a mouse orbit script 1 Answer
Smooth transition of camera targets 2 Answers