creazione siti web venezia

Unity 3D Game Engine – JS – Camera – Swap Multi Cameras – On Click

Unity 3D Game Engine – JS – Camera – Swap Multi Cameras – On Click

1. Create in the Hierarchy

– CameraTarget1 (Empty object)
– CameraTarget2 (Empty object)

– Main Camera> attach ‘CameraControl.js’

CameraControl.js:


#pragma strict

// ########################################################################################
// This complete script can be attached to a camera to change his Position and his Target
// You will move the camera by clicking GUI.Button CAMERA 1 and GUI.Button CAMERA 2
// ########################################################################################

// The relative speed at which the camera will catch up
// Small value = more steps to reach the new position
public var smooth : float = 1.5f;  

// Camera positions START ##################################################################
public var newPosCam1 : Vector3;   // Camera Position 1 
public var newPosCam2 : Vector3;   // Camera Position 2 
// Camera positions END ####################################################################

// Camera targets START ####################################################################
// The target variable shows up as a property in the inspector. 
// Drag another object onto it to make the camera look at it.
var target1 : Transform; 
var target2 : Transform;
// Camera targets END ######################################################################

function Start () {

}


function Update() {
	
}

// NOTICE: function OnGUI is outside others functions
// Move the Camera START ###################################################################	
function OnGUI () {
    // Button color and opacity setup START ################################################
    // 0.0f rende il bottone completamente trasparente, il tocco funziona ugualmente
    GUI.color = new Color(1,1,1,0.5f); 
    // Button color and opacity setup END ##################################################
    
    // Insert 8 pixels of space between the 2 buttons.
	GUILayout.Space (8);

   if (GUI.Button (Rect (600,10,200,200), "CAMERA 1")) {
        transform.position = Vector3.Lerp(transform.position, newPosCam1, smooth * Time.deltaTime);
        transform.LookAt(target2);
    }
   if (GUI.Button (Rect (600,250,200,200), "CAMERA 2")) {
        transform.position = Vector3.Lerp(transform.position, newPosCam2, smooth * Time.deltaTime);
        transform.LookAt(target1);
    }
}
// Move the Camera END #####################################################################

Main Camera> CameraControl.js:

– var Smoot: Small value = more steps to reach the new position

– New Pos Cam 1: first position of camera
– New Pos Cam 2: second position of camera

– Target 1: target of first position -> DRAG AND DROP from Hierarchy to Inspector CameraTarget1 (Empty object)
– Target 2: target of second position -> DRAG AND DROP from Hierarchy to Inspector CameraTarget2 (Empty object)

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – JS – Camera – Swap Multi Cameras – On Click

Unity 3D – Pathfinding – NavMesh Obstacles

Unity 3D – Pathfinding – NavMesh Obstacles

These items are not baked into the NavMesh, and thus can move around freely while getting in the way.
Questi ostacoli non possono essere attraversati dal’agente, non sono calcolati nel NavMesh e si possono muovere liberamente nella scena.

1. Create a NavMesh
2. Create a ‘targetNavigation’ object
3. Create a NavMeshAgent

4. Create a game object and name it ‘moving obstacle’

Select ‘moving obstacle’ Inspector> ‘Add component’> Navigation> Nav Mesh Obstacle setup

– Radius: radius of the obstacle collider
– Height: height of ther obstacle collider
– Move Threshold (soglia):
– Carve (intagliare):

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D – Pathfinding – NavMesh Obstacles

Unity 3D – JS Script – Screen Fader

Unity 3D – JS Script – Screen Fader

1. MAIN TOP MENU> GameObject> Create Other> GUI TEXTURE> Inspector, rename it ‘ScreenFader’
2. Inspector> Transform> Position X=0 Y=0 Z=0 (così viene posizionata in basso a sinistra dello schermo)
3. Pixel Inset, X=0 Y=0 W=0 H=0 (non vogliamo che ci siano dei rientri)
4. Inspector> GUI Texture> DRAG E DROP a black bitmap Texture
5. Assign to ‘ScreenFader’ GameObject this JS Script:

SceneFadeInOut.js

#pragma strict

public var fadeSpeed : float = 1.5f;            // Speed that the screen fades to and from black.
private var sceneStarting : boolean = true;     // Whether or not the scene is still fading in.

function Awake ()
{
    // Set the texture so that it is the size of the screen and covers it.
    // Per prima cosa ricopro tutto lo schermo creando un rettangolo di dimensione dello schermo
    guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
}


function Update ()
{
    // If the scene is starting...
    // Controlla il valore booleano -sceneStarting- se è vero esegue le istruzioni all'interno di -if-
    if(sceneStarting)
        // ... call the StartScene function.
        // richiama la funzione
        StartScene();
}


function FadeToClear ()
{
    // Lerp (interpolate 2 values) the colour of the texture between itself and transparent.
    // Esegue un fading - colore della texture -> completamente trasparente -
    guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime);
}


function FadeToBlack ()
{
    // Lerp (interpolate 2 values) the colour of the texture between itself and black.
    guiTexture.color = Color.Lerp(guiTexture.color, Color.black, fadeSpeed * Time.deltaTime);
}


function StartScene ()
{
    // Fade the texture to clear.
    FadeToClear();
    
    // If the texture is almost clear...
    // Se il colore è quasi completamente trasparente
    if(guiTexture.color.a <= 0.05f)
    {
        // ... set the colour to clear and disable the GUITexture.
        // Rendi il colore completamente trasparente e disabilita la GUI Texture
        guiTexture.color = Color.clear;
        guiTexture.enabled = false;
        
        // The scene is no longer starting.
        // Imposta la variabile booleana a falso per interrompere il ciclo
        sceneStarting = false;
    }
}


public function EndScene ()
{
    // Make sure the texture is enabled.
    guiTexture.enabled = true;
    
    // Start fading towards black.
    FadeToBlack();
    
    // If the screen is almost black...
    if(guiTexture.color.a >= 0.95f)
        // ... reload the level.
        Application.LoadLevel(0);
}

Inspector> SceneFadeInOut.js> ‘Fade Speed’ variable, assign 0.5 (valore basso -> tempo di fading alto)

NOTICE:

Application.LoadLevel(0);

Setup the correct level number, you can find it inside MAIN TOP MENu> File> Build Settings…
If you have only one scene in your project, just reload it -> .LoadLevel(0)

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D – JS Script – Screen Fader

Unity – Spaceship Shooting Game – JS – Audio

Unity – Spaceship Shooting Game – JS – Audio

Asteroid Explosion

Project> Assets> Audio> explosio_asteroid.wav DRAG AND DROP over Prefabs> VFX> Explosions> explosion_asteroid

Prefabs> VFX> Explosions> explosion_asteroid> Inspector> Audio Source> check ‘Play on Awake’, the wav it will be played automatically.

When the VFX explosion_asteroid is instanced the Audio Sopurce Component will play xplosio_asteroid.wav automatically.

Player Explosion

The same procedure as above

Weapon Player

Project> Assets> Audio> weapon_player.wav DRAG AND DROP over Hierarchy> Player

Hierarchy> Player> Audio Source> uncheck ‘Play on Awake’

Hierarchy> Player> PlayerController.js

#pragma strict

class Boundary
{
    // Theese variables are public to make the code easy-reusable
    // You can setup theese variables from Inspector
    var xMin : float;
    var xMax : float;
    var zMin : float;
    var zMax : float;
}

var speed : float;
var tilt : float;
var boundary : Boundary;

var shot : GameObject;     // Inspector -> assign Bolt Prefab
var shotSpawn : Transform; // Inspector -> assign Shot Spawn Empty Object
var fireRate : float;      // Inspector -> 0.25 (seconds) = 4 shot per second

private var nextFire : float;

function Update () {
    // Get Input Fire button
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
        nextFire = Time.time + fireRate;
        // Return the clone of the GameObject, position, rotation if user click Fire button 
        Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
        audio.Play ();
    }
}

function FixedUpdate () {
     // Get User Input START
     var moveHorizontal : float= Input.GetAxis ("Horizontal");
     var moveVertical : float= Input.GetAxis ("Vertical");
     // Get User Input END

     // Move the GameObject
     var movement : Vector3= new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rigidbody.velocity = movement * speed;

    // Limitate movement inside the screen START
    rigidbody.position = new Vector3 
    (
        Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 
        0.0f, 
        Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    );
    // Limitate movement inside the screen END

    // Tilt movement START
    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    // Tilt movement END
}

Notice:

if (Input.GetButton("Fire1")...
...
audio.Play ();
}
...

Audio play… if fire button is pressed!

Background Music

Project> Assets> Audio> music_background.wav DRAG AND DROP over Hierarchy> Game Controller

Hierarchy> Game Controller> Audio Source> check ‘Play on Awake’, check ‘Loop’

Balacing Audio

To setup audio volume open the Audio Source Component> Volume, setup this.

By |Unity3D, Video Games Development|Commenti disabilitati su Unity – Spaceship Shooting Game – JS – Audio

JQuery Corso Base OnLine – Effects – hide-show

Lezione #id-jq-2013-0003#
Un effetto JQuery molto popolare è hide e la controparte show.

By |JQuery, Web Design|Commenti disabilitati su JQuery Corso Base OnLine – Effects – hide-show