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);
}
}
}