OnMouseOver GUI flickering if mouse moves Y

Hey Community.

I have a strange “flickering-problem” with GUI-elements. I’ve build a small c# script for collectable items. If the mouse hovers over an object a gui appears with some infos. It works so far, but if you move the mouse in Y the GUI is flickering. Did not find something to fix that in forum/answers…

Here’s the code:
using UnityEngine;
using System.Collections;

public class MakeItem : MonoBehaviour {

	// Definition
	public string name; // Name of that THING
	public string description; // Tell something about it
	public float weight = 1; // WTF is it so heavy? in kg
	public int slotType; // Where to put this shit (1=Backpack, 2=Toolbelt, 3=?)
	public int slotSize = 1; // Damn this takes a lot of place
	public int use = 1; // Can I use it? Throw it? Put it in my hand?
	public int stackSize = 1; // Stack it if you want, bro
	public float spawnrate; // Limit the spawnrate to INFINITE ;)	
	public int condition = 100; // good, weak? in percent
	public Texture2D icon;	
	
	private bool showItemInfos = false;
	
	void OnMouseOver() {
		showItemInfos = true;
	}
	
	void OnMouseExit() {
		showItemInfos = false;
	}
	
	void OnGUI() {
		if(showItemInfos) {
			int y;
			// get mouse position
			Vector3 mousePosition = Input.mousePosition;		
			
			// Draw some infos
			GUI.Box(new Rect(mousePosition.x,Screen.height- mousePosition.y, 100, 100), description);
			//print ("X: " + mousePosition.x + " Y: " + mousePosition.y);
			
			// show item infos
			GUI.BeginGroup(new Rect(Screen.width - 210, 10, 200, 200));
				// draw a box as border
				GUI.Box(new Rect(0, 0, 200, 200), name);
				y = 20;
				GUI.DrawTexture(new Rect(5, y, 50, 50), icon);
				y += 50;
				GUI.Label(new Rect(5, y, 200, 20), "Description: " + description);
				y += 20;
				GUI.Label(new Rect(5, y, 200, 20), "Weight: " + weight);
				y += 20;
				GUI.Label(new Rect(5, y, 200, 20), "Condition: " + weight);
			GUI.EndGroup();
			//print ("X: " + transform.position.x + " Y: " + transform.position.y);
			//GUI.Label(Rect(mousePosition.x, mousePosition.y), name);
		}
	}
}

Have you thought about doing this as tooltips instead?

Not quite sure how your inventory system is setup, is it all GUI elements that you display or are the inventory objects 3D? If your doing the inventory objects as GUI try this:

GUI.Label (new Rect (0,0,25,25), new GUIContent ("Item Name" "ToolTip Info"), gameStyle.getStyle("customGUISkinTexture");

GUI.Label (new Rect (Input.mousePosition.x,(Screen.height - Input.mousePosition.y) - 20, GUI.tooltip.Length * 12 ,30),GUI.tooltip, gameStyle.GetStyle("whitetext"));

All this are normal GUI elements. Why should I realize this with tooltips? Its working, just flickering. I guess thats not normal.

any other ideas?

An old question but i just ran into this and my fix was to off set the x and y.

GUI.Box(new Rect(mousePosition.x + 2,Screen.height- mousePosition.y + 2, 100, 100), description);

I ran into flickering where the component with IPointerEnterHandler and IPointerExitHandler was flickering enter/exit when moving the mouse.

In my case the component was quite small, and the solution was to add a bit of raycast padding to my image that was receiving the raycasts. I added -5, -5, -5, -5 and this basically solved the issue.