- Home /
OnMouseOver GUI not appearing
objRect.y = Mathf.Abs(MousePos.y - Camera.main.pixelHeight);
Is there a Java equivalent to C#'s Mathf.Abs?
Thank you.
EDIT: This is my complete script, I have another problem!
var ShowRollover; var objRect : Rect; var mousePos : Vector2; var offset : Vector3;
offset = new Vector3(16, 16, 0);
function Update() { ShowRollover = false; objRect = new Rect(0, 0, 500, 100); mousePos = new Vector2(0, 0); }
function OnMouseOver() { ShowRollover = true; }
function OnMouseExit() { ShowRollover = false; }
function OnGUI() { if (ShowRollover) { mousePos = Input.mousePosition + offset; objRect.x = mousePos.x;
GUI.contentColor = Color.yellow;
objRect.y = Mathf.Abs(mousePos.y - Camera.main.pixelHeight);
GUI.Label(objRect, "Name: Common Carp\nNumber of fish in patch: 8");
}
}
I found that if the label cannot be seen even when I'm hovering the mouse over the object with the collider. Is there any mistake that I made?
$$anonymous$$athf.Abs should work in UnityScript.. are you getting an error when you try? If so, can you post it?
Don't set ShowRollover
to false in Update(), and change On$$anonymous$$ouseOver() to On$$anonymous$$ouseEnter().
Answer by Eric5h5 · Sep 07, 2010 at 04:37 AM
Mathf.Abs isn't C#, it's a Unity-specific function (Mathf is a Unity-specific class). System.Math.Abs isn't C# either, it's Mono/.NET. In fact there are no functions that are C#-only. The code you wrote is valid JS. (However Java is not a valid "nickname" for Javascript, as it's a different language entirely, and not used in Unity.)