Video Games Development

Unity – Scene View Navigation

Unity – Scene View Navigation

SCENE VIEW

MAIN TOP MENU> Window> Scene

Shortcuts View:

Q + LMB -> PAN VIEW
Q + RMB -> LOOK AROUND FIRST PERSON STYLE
ALT + LMB -> LOOK AT
ALT + RMB -> ZOOM

Shortcuts Objects:

F -> FOCUS CURRENT OBJECT
W + LMB -> MOVE OBJECT
E + LMB -> ROTATE OBJECT
R + LMB -> SCALE OBJECT

Menu:

Textured
Wireframe
Textured Wireframe
Render Path
LightMap Resolution

RGB
Alpha
Overdraw
Mipmaps

2D
3D

Light ON/OFF

Audio ON/OFF

Effects Skybox / Fog / Flares / Animated Material

Gizmos / Grid SETUP

SEARCH Object

WIEW GIZMO (to switch in ‘perspective view’ mode click over the white box)

GAME VIEW

2. MAIN TOP MENU> Window> Game

Menu:

Free Aspect
5:4
4:3
3:2
16:10
16:9

Standalone (1024×768) setup this:
Edit> Project Settings> Player> Inspector> Settings for PC, MAc LinuX Standalone
Uncheck ‘Default is Full Screen’ and setup ‘Default Screen Width’ and ‘Default Screen Height’

Mazimize on Play

Stats
Verts, VRAM etc…

Gizmos / Grid SETUP

By |Unity3D|Commenti disabilitati su Unity – Scene View Navigation

Unity – Object follow cursor pointer

Unity – Object follow cursor pointer

DRAG AND DROP this script over an Object inside Hierarchy

#pragma strict

function Start () 
{ 
 Screen.showCursor = false; 
} 

// -------------------------------
// FOLLOW MOUSE POSITION START
// -------------------------------
public var depth = 10.0; 

function FollowMousePosition()
{ 
 var mousePos = Input.mousePosition; 
     var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth)); 
     transform.position = wantedPos; 
}
// -------------------------------
// FOLLOW MOUSE POSITION END
// -------------------------------

function Update () 
{ 
 FollowMousePosition();  
}

NOTICE: mousePos.x – mousePos.y

By |Unity3D|Commenti disabilitati su Unity – Object follow cursor pointer

Unity – LookAt 2D – Mouse Position

Unity – LookAt 2D – Mouse Position

Instead of ‘Transform.LookAt’ Unity function you can use Mathematic.

1. DRAG AND DROP this script over the object you want to look at target

var mouse_pos : Vector3;
var target : Transform; //Assign to the object you want to rotate
var object_pos : Vector3;
var angle : float;
 
function Update ()
{
    mouse_pos = Input.mousePosition;
    mouse_pos.z = 5.23; //The distance between the camera and object
    object_pos = Camera.main.WorldToScreenPoint(target.position);
    mouse_pos.x = mouse_pos.x - object_pos.x;
    mouse_pos.y = mouse_pos.y - object_pos.y;
    angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
    transform.rotation = Quaternion.Euler(Vector3(0, 0, angle));
}

2. Inspector> select the target for the variable ‘Target’
3. Play!

By |Unity3D|Commenti disabilitati su Unity – LookAt 2D – Mouse Position

Unity – Look At 3D – Mouse Position

Unity – Look At 3D – Mouse Position

The Code:

        // Performs a mouse look.
	var horizontalSpeed : float = 2.0;
	var verticalSpeed : float = 2.0;
	
	function Update () {
		// Get the mouse delta. This is not in the range -1...1
		var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");
		var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");
		transform.Rotate (v, h, 0);
	}
By |Unity3D|Commenti disabilitati su Unity – Look At 3D – Mouse Position

Unity – Repeiting a function

Unity – Repeiting a function

Invoke Repeat

#pragma strict
 
var x: int;

function Start()
{
    // InvokeRepeiting (function name, delay time in seconds, repeat every x seconds...)
    InvokeRepeating("myFunction", 2, 1);
}

function myFunction()
{
    var x = x++;
    Debug.Log("Invoked " + x);
}

The result is:

Invoked 0
Invoked 1
Invoked 2
Invoked 3
… to infinity and beyond!

Cancel Invoke

        // Starting in 2 seconds.
	// a projectile will be launched every 0.3 seconds
	var projectile : Rigidbody;
	InvokeRepeating("LaunchProjectile", 2, 0.3);

	// Cancels the repeating invoke call, 
	// when the user pressed the ctrl button
	function Update() {
		if (Input.GetButton ("Fire1"))
			CancelInvoke("LaunchProjectile");
	}
	function LaunchProjectile () {
		instance = Instantiate(projectile);
		instance.velocity = Random.insideUnitSphere * 5;
	}
By |Unity3D|Commenti disabilitati su Unity – Repeiting a function