Video Games Development

Unity – Build a Game – Basics

Videogames Development – Unity – How to build a videogame

A videogame project can be built for:

– Web Player
– Flash Player

– Google Native Client

– PC Standalone
– Mac Standalone
– Linux Standalone

– Windows Store Apps

– IOS
– Android
– Black Berry
– Windows 8 Phone

– XBox 360
– PS3
– Wii

BUILD A GAME

Load a Project

1. MAIN TOP MENU> File> Build Settings…> Choose your platform

2. MAIN TOP MENU> File> Build Settings…> ‘Player Setting’ button> Inspector setup ‘PlayerSetting’, the most important are:

– Company Name
– Product Name
– Default Icon> ‘Select Button’> choose a Asset in the list
– Default Cursor

– Resolution and Presentation> Supported Aspect Ratios
– Icon
– Spalsh Image
– Other Settings

3. MAIN TOP MENU> File> Build Settings…> ‘Buid’ or ‘Build and Run’> Choose a folder to save the game.

4. Close the ‘Build Settings’ window using the red cross on top right.

Open the folder where the games has benn saved and… great! Now you can play your own game!

By |Unity3D|Commenti disabilitati su Unity – Build a Game – Basics

Unity – BG Music

Videogames Development – Unity – How to add a background music

LOAD A BG MUSIC

1. MAIN TOP MENU> Edit> Assets> Import New Asset…> your-bgmusic.mp3
2. DRAG AND DROP ‘your-bgmusic.mp3’ from ‘Project’ window to ‘Scene’ viewport

MODIFY A BG MUSIC

1. Hierarchy> select your-bgmusic.mp3
2. InspectorA setup parameters

SETUP CAMER TO LISTEN MUSIC

1. Hierarchy> select Main Camera
2. Inspector> check Audio Listener

NOTICE:
The Audio Listener acts as a microphone-like device. It receives input from any given Audio Source in the scene and plays sounds through the computer speakers.

By |Unity3D|Commenti disabilitati su Unity – BG Music

Unity – Scripting – If Statements

Videogames Development – Unity – If Statements (dichiarazioni If)

IF – ELSE

if (1 == a)
{
             // Do a set of actions
}
else
{
             // Do another set of actions
}

IF – ELSE IF

if (1 == a)
{
             // Do a set of actions
}
else if (2 -- b)
{
             // Do another set of actions
}
else
{
             // Do YET another set of actions
}

IF – NESTED (annidato)

if (1 == a)
 {
     if (2 ==b)
      {
             // Do a set of actions
      }
}
By |Unity3D|Commenti disabilitati su Unity – Scripting – If Statements

Unity – Scripting – Debug

Videogames Development – Unity – Debug.Log

Logs message to the Unity Console.

Statements:

// Message with a link to an object.
Debug.Log ("Hello", gameObject);

// Message using rich text.
Debug.Log("<color=red>Fatal error:</color> AssetBundle not found");

SCRIPT

MAIN TOP MENU> ASSETS> CREATE> Javascript, type the name ‘GetMousePosition’

Assets> GetMousePosition> Inspector> ‘Open…’ button

Write:

#pragma strict

function Start () {

}

function Update () {
	var mouse = Input.mousePosition;
        Debug.Log(mouse);
		
	}

Create an Object inside the Hierarchy ‘MyObject’

Assets> DRAG AND DROP ‘GetMousePosition’ script over Hierarchy> MyObject

Play> move the mouse, look at the BOTTOM OF THE SCREEN, you will see the coordinates as: (536.0, 583.0, 0.0)

By |JavaScript, Unity3D, Video Games Development|Commenti disabilitati su Unity – Scripting – Debug

Unity – Scripting – Array

Videogames Development – Unity – Array

An Array stores multiple values in a single variable.
The first array’s value is 0.

There are two types of arrays in Unity:
1- builtin arrays and normal Javascript Arrays
2- builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized

Javascript Arrays

Assign this code to an Empty Object in the Scene:

#pragma strict

function Start()
{
    
}

function Update()
{
// Array Start
var mycars = new Array();
mycars[0] = "Saab"; // Notice: the first value is 0
mycars[1] = "Volvo";
mycars[2] = "BMW";
// Array End
 var i= 1; // Array index
 Debug.Log(mycars[i]); // The result is Volvo
}

Javascript Arrays: Print an Array Content

#pragma strict

function Start () 
{
    var strings = ["First string", "Second string", "Third string"];
    
    for(var item : String in strings)
    {
        print (item);
    }
}

Javascript Arrays: basic use

var myArray = new Array();     // declaration
myArray.Add(anItem);           // add an item to the end of the array
var thisItem = myArray[i];     // retrieve an item from position i (richiamare un contenuto dalla posizione i)
myArray.RemoveAt(i);           // removes an item from position i
var howBig = myArray.length;   // get the length of the Array

.NET Arrays

Syntax 1 – multiple lines

#pragma strict

// type [] name = new Array type[number of items]
int[] myIntArray = new Array int[3];

function Start () 
{
// name of array[index] = value
myIntArray[0] = 12;
myIntArray[1] = 16;
myIntArray[2] = 18;
}

Syntax 2 – one line

#pragma strict

// type [] name = new Array type[number of items]
int[] myIntArray = {12, 16, 18};

function Start () 
{

}

Public Array – you can see them in Inspector window

The code below creates an Array of Game Objects with Tag ‘Player’

#pragma strict

public var players : GameObject[];

function Start ()
{
    players = GameObject.FindGameObjectsWithTag("Player");
    
    for(var i : int = 0; i < players.Length; i++)
    {
        Debug.Log("Player Number "+i+" is named "+players[i].name);
    }
}
By |Unity3D|Commenti disabilitati su Unity – Scripting – Array