Unity 3D – On Click – Emit Particles

Unity 3D – On Click – Emit Particles

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

2. Hierarchy> select the Cube> Inspector> ‘Add Component’> Effects> Partycle System> UNCHECK ‘Play On Awake’

3. Hierarchy> select the Cube> Inspector> ‘Add Component’> New Script> OnClick.JS

OnClick.JS:


#pragma strict
 
function Start () {
 
}
 
function OnMouseDown ()
{
        // When you click over the object
        // the particle system will emit 5 particles
        particleSystem.Emit(5);
}
 
function Update () {
 
}

NOTICE: the components structure into Inspector will be:

– Cube
– Cube (Mesh Filter)
– Box Collider -> there is no ‘OnMouseDown’ effect without it!
– Mesh Renderer
– Particle System
– OnClick.JS -> it calls particleSystem as effect attached to the Object

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D – On Click – Emit Particles

Unity 3D Game Engine – Particles follow Cursor Pointer

Unity 3D Game Engine – Particles follow Cursor Pointer

1. MAIN TOP MENU> Main Object> Create Other> Particle System

2. Inspector> Particle System> Add Component> New Script> FollowMouse.JS

3. FollowMouse.JS


#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();  
}

4. Inspector> Setup the Partycle System to create a fairy dust effect:

Particle System

– Start Size: 0.3
– Gravity Multiplier: 1
– Simulation Space: World -> really important!!!

Emission: check it

– Rate: 30

Shape: check it

– Shape: Sphere
– Radius 0.1

Limit Velocity over Lifetime: check it

– Speed: 3
– Dampen: 1

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Particles follow Cursor Pointer

Unity 3D Game Engine – Real Time In Game Clock

Unity 3D Game Engine – Real Time In Game Clock

1. Hiearchy> GUI Text, choose a font or download it from http://www.1001freefonts.com/3d-fonts.php

2. Hierarchy> Main Camera, attach ‘Clock.js’

Clock.js


#pragma strict

var ClockText  : GUIText;  // Hierarchy DRAG E DROP over var GUI Text in Inspector  
private var dt = Date();
 
 
function Update () {
 
var day = dt.Now.Day;
var month = dt.Now.Month;
var year = dt.Now.Year;
var hours = dt.Now.Hour;
var minutes = dt.Now.Minute;
var seconds = dt.Now.Second;
 
ClockText.text = day + " " + month + " " + year + " " + hours + " " + minutes + " " + seconds;
 
}

Hierarchy> Main Camera> Inspector> Clock.js, assign GUI Text

Today, the result is:

16 5 2014 10 40 32

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Real Time In Game Clock

Unity 3D Game Engine – Scripting Javascript – ExecuteInEditMode

Unity 3D Game Engine – Scripting Javascript – ExecuteInEditMode

In Unity gli script vengono eseguiti solamente se viene attivato il pulsante ‘Play’
@ExecuteInEditMode esegue a video lo script anche in fase di editing, senza dover cliccare su ‘Play’.
Usare questa funzione con attenzione perchè lo script risulta sempre attivo.


#pragma strict

@ExecuteInEditMode // esegui lo script anche in modalità di editing del progetto
function Start () 
{
    renderer.sharedMaterial.color = Color.red;
}

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Scripting Javascript – ExecuteInEditMode

Unity 3D Game Engine – Attributes Range – JavaScript

Unity 3D Game Engine – Attributes Range – JavaScript

@Range(-100, 100) // Aggiunge uno slide per il setup della variabile in Inspector


#pragma strict

@Range(-100, 100) // Aggiunge uno slide per il setup della variabile in Inspector
public var speed : int = 0;

function Update () 
{
    transform.Rotate(new Vector3(0, speed * Time.deltaTime, 0));
}

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Attributes Range – JavaScript