Unity – Scripting – OnGUI – Label
Videogames Development – Unity – Code GUI Objects – Label (Etichette non interattive)
Labels have no user interaction, do not catch mouse clicks and are always rendered in normal style. If you want to make a control that responds visually to user input, use a Box control.
Text Label
1. Assign the script to the Camera:
#pragma strict function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "Hello World!"); }
Statement:
GUI.Label (Rect (10, 10, 100, 20), “Hello World!”);
GUI.Label (Rect (x, y, x, y), “text content”);
Image Label
1. Assign the script to the Camera:
#pragma strict // Texture Label START var textureToDisplay : Texture2D; function OnGUI () { GUI.Label (Rect (10, 40, textureToDisplay.width, textureToDisplay.height), textureToDisplay); } // Texture Label END
2. Select the Camera> ‘Inspector’> Script> DRAG AND DROP a texture from ‘Assets’ to Script> ‘textureToDisplay’ variable.
3. Play and enjoy!
Statement:
GUI.Label (Rect (10, 40, textureToDisplay.width, textureToDisplay.height),textureToDisplay);
GUI.Label (Rectangle (x, y, x, y),textureToDisplay);