unity3d

Unity – Scripting – OnGUI – Toggle (Interruttore)

Unity – Scripting – OnGUI – Toggle (Interruttore)

Videogames Development – Unity – Code GUI Objects – Toggle (Interruttore)

Text Toggle

1. Assign the script to the Camera:

#pragma strict

        
	// Text Toggle START
        private var toggleTxt : boolean = false;
	function OnGUI () {
	if (GUI.Toggle(Rect(10, 10, 100, 30), toggleTxt, "A Toggle text")) {
		print ("You clicked the toggle!");
	}
        // Text Toggle END
}

Statement:
GUI.Toggle(Rect(10, 10, 100, 30), toggleTxt, “A Toggle text”
GUI.Toggle(Rect(x, y, x, y), bool, “text content”

Image Toggle – Use images as buttons

1. Assign the script to the Camera:

#pragma strict
        
    // Image Toggle START
	var aTexture : Texture;
	
    private var toggleImg : boolean = false;
    
	function OnGUI () {
	// Assign image from Inspector Controller
	if(!aTexture) {
			Debug.LogError("Please assign a texture in the inspector.");
			return;
		}
	if (GUI.Toggle(Rect(10, 50, 50, 50), toggleImg, aTexture)) {
		print ("You clicked the toggle!");
	}
    // Image Toggle END
}

2. Select the Camera> ‘Inspector’> Script> DRAG AND DROP a texture from ‘Assets’ to Script> ‘ATexture’ variable.

3. Play and enjoy!

By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Toggle (Interruttore)

Unity – Scripting – GUITexture

Unity – Scripting – GUITexture

Unity – Scripting – GUITexture (get from gui and code it)

GUI Texture

1. MAIN TOP MENU> GameObject> Create Other> GUI Texture

2. The text will create the GameObject ‘UnityWatermark-small’ in the Viewport

3. Project> Assets, select ‘UnityWatermark-small’> Inspector, setup the texture default parameters

4. Attach this JS Script at GameObject ‘GUI Text’:

#pragma strict
 
        // Assign someTexture to the guiTexture
	var someTexture : Texture2D;
	guiTexture.texture = someTexture;   

5. DRAG AND DROP a Texture from Assets to Inspector> GUITexture> JS Script> Some Texture

Properties List

border The border defines the number of pixels from the edge that are not affected by scale.
color The color of the GUI texture.
pixelInset Pixel inset used for pixel adjustments for size and position.
texture The texture used for drawing.

By |Unity3D|Commenti disabilitati su Unity – Scripting – GUITexture

Unity – Scripting – GUIText

Unity – Scripting – GUIText

Unity – Scripting – GUIText (get from gui and code it)

GUI Text

1. MAIN TOP MENU> GameObject> Create Other> GUIText

2. The text will create the GameObject ‘GUI Text’ in the Viewport

3. Project> Assets, select the text> Inspector, setup the text

4. Attach this JS Script at GameObject ‘GUI Text’:

#pragma strict
 
 guiText.text = "Hello Monkey!";         

5. Play and you will see “Hello Monkey!”

Properties List

alignment The alignment of the text. It is object pivot-based
anchor The anchor of the text.
color The color used to render the text.
font The font used for the text.
fontSize The font size to use (for dynamic fonts).
fontStyle The font style to use (for dynamic fonts).
lineSpacing The line spacing multiplier.
material The Material to use for rendering.
pixelOffset The pixel offset of the text.
richText Enable HTML-style tags for Text Formatting Markup.
tabSize The tab width multiplier.
text The text to display.

By |Unity3D|Commenti disabilitati su Unity – Scripting – GUIText

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