Unity – Scripting – OnGUI – Settings

Unity – Scripting – OnGUI – Settings

Videogames Development – Unity – Code GUI Objects – Settings

Inside Text Area, selected text comes in with cyan highlight.

1. Assign the script to the Camera:

#pragma strict
     
	// Sets the selection color to cyan
	var str : String = "This is a string with\ntwo lines of text";
	function OnGUI() { 
		GUI.skin.settings.selectionColor = Color.cyan;
		str = GUILayout.TextArea(str);
	}

Setting List:

GUI.skin.settings.selectionColor = Color.cyan;

.selectionColor The color of the selection rect in text fields.
.cursorColor The color of the cursor in text fields.
.cursorFlashSpeed The speed of text field cursor flashes.
.doubleClickSelectsWord Should double-clicking select words in text fields.
.tripleClickSelectsLine Should triple-clicking select whole text in text fields.

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Settings

Unity – Scripting – OnGUI – Label

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

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Label

Unity – Scripting – OnGUI – Input Text Field

Unity – Scripting – OnGUI – Input Text Field

Videogames Development – Unity – Code GUI Objects – Input Text Field

Input Text Field

1. Assign the script to the Camera:

#pragma strict

        var stringToEdit : String = "Hello World";
	function OnGUI () {
		// Make a text field that modifies stringToEdit.
		stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
	}

2, Play and type text inside the Text Area

Statement:
GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
GUI.TextField (Rect (x, y, x, y), text content, max lenght);

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Input Text Field

Unity – Scripting – OnGUI – Text Area

Unity – Scripting – OnGUI – Text Area

Videogames Development – Unity – Code GUI Objects – Input Text Area

Input Text Area

1. Assign the script to the Camera:

#pragma strict

	var stringToEdit : String = "Hello World\nI've got 2 lines...";
	function OnGUI () {
		// Make a multiline text area that modifies stringToEdit.
		stringToEdit = GUI.TextArea (Rect (10, 10, 200, 100), stringToEdit, 200);
	}

2, Play and type text inside the Text Area

Statement:
GUI.TextArea (Rect (10, 10, 200, 100), stringToEdit, 200);
GUI.TextArea (Rect (x, y, x, y), text content, max lenght);

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Text Area

Unity – Scripting – OnGUI – Box

Unity – Scripting – OnGUI – Box

Videogames Development – Unity – Code GUI Objects – Box

Input Text Area

1. Assign the script to the Camera:

#pragma strict
     
    // Draws a box of the size of the screen.
    var stringBox : String = "Hello World\nI've got 2 lines...";
	function OnGUI() {
		 GUI.Box(Rect(0,0,Screen.width,Screen.height),"This is a title");
	}

Statement:
GUI.Box(Rect(0,0,Screen.width,Screen.height),”This is a title”);
GUI.Box(Rectangle(x,y,x,y),text content);

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Box