unity3d

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

Unity – Scripting – OnGUI – Buttons

Unity – Scripting – OnGUI – Buttons

Videogames Development – Unity – Code GUI Objects – Buttons

UnityGUI allows you to create a wide variety of highly functional GUIs very quickly and easily. Rather than creating a GUI object, manually positioning it, and then writing a script that handles its functionality, you can do everything at once with just a few lines of code. The code produces GUI controls that are instantiated, positioned and handled with a single function call.

Simple Text Button

1. Assign the script to the Camera:

#pragma strict

function Start () {

}

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		print ("You clicked the button!");
	}
}

function Update () {

}

Statement:
GUI.Button (Rect (10,10,150,100), “I am a button”)
GUI.Button (Rectangular (x topleft,y topleft,x bottomright,y bottomright), “Button Text”)

Image Button

1. Assign the script to the Camera:

#pragma strict

	var btnTexture : Texture;
	function OnGUI() {
                // Texture Controller
		if (!btnTexture) {
			Debug.LogError("Please assign a texture on the inspector");
			return;
		}
		if (GUI.Button(Rect(10,10,150,100),btnTexture))
			Debug.Log("Clicked the button with an image");
	}

2. Select the Camera> ‘Inspector’> Script> DRAG AND DROP Texture from ‘Assets’ to Script> ‘Btn Texture’ variable.

3. Play and enjoy!

Multiple Buttons

1. Assign the script to the Camera:

Left Side Bar:

#pragma strict

	function OnGUI() {

        // Multiple Buttons - Left Side Bar
		if (GUI.Button(Rect(10,10,50,50),"BTN1"))
			Debug.Log("Clicked BTN1");
		if (GUI.Button(Rect(10,70,50,50),"BTN2"))
			Debug.Log("Clicked BTN2");
		if (GUI.Button(Rect(10,130,50,50),"BTN3"))
			Debug.Log("Clicked BTN3");
		if (GUI.Button(Rect(10,190,50,50),"BTN4"))
			Debug.Log("Clicked BTN4");
	}

Top Left Bar:

#pragma strict

	function OnGUI() {

        // Multiple Buttons - Top Left Bar
		if (GUI.Button(Rect(10,10,50,50),"BTN1"))
			Debug.Log("Clicked BTN1");
		if (GUI.Button(Rect(70,10,50,50),"BTN2"))
			Debug.Log("Clicked BTN2");
		if (GUI.Button(Rect(130,10,50,50),"BTN3"))
			Debug.Log("Clicked BTN3");
		if (GUI.Button(Rect(190,10,50,50),"BTN4"))
			Debug.Log("Clicked BTN4");
	}
By |Unity3D|Commenti disabilitati su Unity – Scripting – OnGUI – Buttons

UNITY – 3D Physic – Joints

UNITY – 3D Physic – Joints

Using Joints

Fixed Joint – Spring Joints

1. MAIN TOP MENU> GameObject> Capsule1
– Capsule Collider (Inspector> ‘Add Component’> Physics> Capsule Collider)
– Rigid Body (Inspector> ‘Add Component’> Physics> Rigid Body)
– Fixed Joint (Inspector> ‘Add Component’> Physics> Fixed Joint)

Inspector ‘Add Component’>

2. In the viewport under Capsule 1 create
MAIN TOP MENU> GameObject> Capsule2
– Capsule Collider (Inspector> ‘Add Component’> Physics> Capsule Collider)
– Rigid Body (Inspector> ‘Add Component’> Physics> Rigid Body)
– Spring Joint> Connected Body> Capsule1 (Inspector> ‘Add Component’> Physics> Spring Joint)

3. In the viewport under Capsule 2 create
MAIN TOP MENU> GameObject> Capsule3
– Capsule Collider
– Rigid Body
– Spring Joint> Connected Body> Capsule2

The final structure is:

Capsule1 -> Collider + Rigid Body + Fixed Joint
|
Capsule2 -> Collider + Rigid Body + Spring Joint
|
Capsule3 -> Collider + Rigid Body + Spring Joint

Sping Joint Parameters

Anchor: setup the pivot point of the joint (the orange dot in the scene view)

Spring: (molla) 1= soft spring (molla debole), 10= tight spring (molla più rigida), infinity= no spring (molla infinitamente rigida)

Damper: (ammortizzatore)

Min Distance: minimum lenghth of the spring

Max Distance: maximun lenghth of the spring

Break Force: forza da applicare per rompere il vincolo

Break Torque: momento torcente da applicare per rompere il vincolo

Hinge Joints

Hinge Joints are useful to make doors, windows etc..

Create a Box -> apply: Collider + Rigid Body + Hinge Joint

Hinge Joint Parameters

Anchor: setup the pivot point of the joint (the orange dot in the scene view)

Axis: the joint axis, example: to open a door X=0 Y=1 Z=0

Motor: example-> move a automatic gate-> check ‘Use Motor’, Target Velocity:5 Force:4

Limits: example-> limit the door opening-> check ‘Use Limits’, Limits Min:0 Max:90

Break Force: forza da applicare per rompere il vincolo

Break Torque: momento torcente da applicare per rompere il vincolo

By |Unity3D|Commenti disabilitati su UNITY – 3D Physic – Joints