- Home /
Question by
Datfreeman · Nov 01, 2013 at 08:20 PM ·
mouseguitextcursor-customization
Offseting position of guiText in relation to mouse
var cursorImage : Texture2D;
var SelectedGUIText:Transform;
var TextoffsetX: float = 0.1;
var TextoffsetY: float = 0.1;
var cursorSizeX : int = 16;
var cursorSizeY : int = 16;
function Start()
{
Screen.showCursor = false;
}
function OnGUI(){
GUI.DrawTexture (Rect(Event.current.mousePosition.x-cursorSizeX/2, Event.current.mousePosition.y-cursorSizeY/2, cursorSizeX, cursorSizeY), cursorImage);
SelectedGUIText.position = camera.main.ScreenToViewportPoint(Input.mousePosition);
}
I am currently using this piece of script to fix a texture to the cursor position as well as a GUIText, but I want to be able to dynamically change the X and Y coordinates of the GUIText in relation to the mouse cursor using the var TextoffsetX: float = 0.1; and var TextoffsetY: float = 0.1;
Comment
Not sure what you are going for here. Just this:
SelectedGUIText.position = camera.main.ScreenToViewportPoint(Input.mousePosition) + Vector2(TextoffsetX, TextoffsetY);
Your answer
