- Home /
Color picker and mouse position
I have an object that has a rotate script. I also have a GUI texture button that when is pressed a color picker appear. I want to disable the rotate function when my mouse is over the color picker.
I came up with this code which is not working.
This function is in the rotate script :
function isCameraInputIgnored () : boolean {
otherScript = Camera.main.GetComponent(colorPicker);
//should be true isf the color picker is present
var mousePos : Vector3 = Input.mousePosition;
// invert the y-coordinate
mousePos.y = Screen.height - mousePos.y;
if (otherScript.colorPickerPresent)
return true; //mouse is over color picker
return false; //if mouse isn't over
}
This function is in the color picker script :
static var colorPickerPresent = false;
static var colorPickerRect : Rect = Rect(820,190,150,150);
function Update(){
var mousePos : Vector3 = Input.mousePosition;
// invert the y-coordinate
mousePos.y = Screen.height - mousePos.y;
print(mousePos.y);
if (colorPickerRect.Contains(mousePos))
colorPickerPresent = true;
colorPickerPresent = false;
}
Answer by syclamoth · Nov 02, 2011 at 03:06 PM
You need an 'else' after your if!
function Update(){
var mousePos : Vector3 = Input.mousePosition;
// invert the y-coordinate
mousePos.y = Screen.height - mousePos.y;
print(mousePos.y);
if (colorPickerRect.Contains(mousePos))
{
colorPickerPresent = true;
} else { // THIS BIT IS VITAL
colorPickerPresent = false;
}
}
What was happening there was, it was checking the mouse position, well and good, but after it did that it then completely ignored the result and set colorPickerPresent to false anyway!
Alternatively, you can just use this one line-
colorPickerPresent = colorPickerRect.Contains(mousePos);
Your answer
Follow this Question
Related Questions
Rotating GUITexture 1 Answer
rotating guiTextures? 1 Answer
Camera rotation around player while following. 6 Answers
Cannot get GUIUtility.RotateAroundPivot working 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer