creazione siti verona

Unity 3D Game Engine – Get Mouse – Draw Line

Unity 3D Game Engine – Get Mouse – Draw Line

1. Main Camera attach the script LineMouse.js

LineMouse.js


#pragma strict

// It automatically adds Add Component> Effects> Line Renderer
@script RequireComponent(LineRenderer)

var lineRenderer : LineRenderer;
var myPoints : Vector3[];

function Start () {
    // Setup of LineRenderer Component
    lineRenderer = GetComponent(LineRenderer);
    lineRenderer.SetWidth(0.2,0.2);
}

function Update () {

    if(myPoints){

        lineRenderer.SetVertexCount(myPoints.Length);
        for(var i = 0;i<myPoints.Length;i++){
            lineRenderer.SetPosition(i,myPoints[i]);    
        }
    }
    else
    lineRenderer.SetVertexCount(0);
    
    if(Input.GetMouseButtonDown(0)){
        // it is only drawing 10 points per second, as per the line
        InvokeRepeating("AddPoint",.1,.1);
    } 
     if(Input.GetMouseButtonUp(0)){
        CancelInvoke();
        myPoints = null;
    }

}

function AddPoint(){

   Debug.Log("Add");

    var tempPoints : Vector3[];

    if(!myPoints)
        tempPoints = new Vector3[1];
    else{
        tempPoints = new Vector3[myPoints.Length+1];
       
    for(var j = 0; j < myPoints.Length; j++)
        tempPoints[j] = myPoints[j];
    
   }   
     var tempPos : Vector3 = Input.mousePosition;
    tempPos.z = 10;
    
    tempPoints[j] = camera.ScreenToWorldPoint(tempPos);
   myPoints = new Vector3[tempPoints.Length];
   for(j=0; j< myPoints.Length; j++) 
   myPoints[j] = tempPoints[j];
}

NOTICE: it seems to be a little sluggish.

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Get Mouse – Draw Line

Unity – Spaceship Shooting Game – JS – Laser Bolt

Unity – Spaceship Shooting Game – JS – Laser Bolt

1. Create the Prefab ‘Bolt’
2. The prefabs needs inside Inspector:
– Transform
– Rigid Body
– Capsule Collider: check ‘Is Trigger’

– Mover.js

#pragma strict

var speed : float; // Assign this inside Inspector

function Start () : void {
    // forward is the Z Axis
    rigidbody.velocity = transform.forward * speed;
}

Inspector> Mover (Script)
– Speed: 20

3. Create a Prefab ‘Player’ (it is the spaceship)
4. Create an Empty Object ‘Shot Spawn’ (produttore di spari)
5. DRAG AND DROP ‘Shot Spawn’ over Hierarchy> ‘Player’, now ‘Shot Spawn’ is child of ‘Player’
6. DRAG AND DROP ‘Bolt Prefab’ over Hierarchy> ‘Shot Spawn’, now ‘Bolt Prefab’ is child of ‘Shot Spawn’

At the end the Hierarchy will be:

Player
– Shot Spawn
– Bolt Prefab

Assign to ‘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);
        // Assign an audio file inside Inspector
        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
}

Hierarchy> Player> Shot Spawn> Bolt CANC to delete
Se non si cancella questo oggetto, all’inizio del gioco la nostra astronave sparerà subito un colpo, invece noi vogliamo che non vengano emessi colpi fino a che il tasto fire resta inutilizzato.

7. MAIN tOP MENU> GameObject> Cube and name it ‘Boundary’
8. Hierarchy> select ‘Cube’> Inspector>
– Transform> small gear icon> Reset
– Mesh Render> uncheck
– Box Collider> check ‘Is Trigger’
9. Scale the box to surround all your game area

10. Create and assign to ‘Boundary’ DestroyByBoundary.js

#pragma strict

// Destroy Game Objects START
function OnTriggerExit(other : Collider)
{
    // Destroy all GameObjects WITH COLLIDER that run away THIS Collider
    // The GameObject WITHOUT COLLIDER will not be detroyed!!!
    Destroy(other.gameObject);
}
// Destroy Game Objects END

11. Hierarchy> ‘Boundary’> Inspector> Remove ‘Mesh Filter”Mesh Renderer’

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

WordPress – Impedire editing pagine

WordPress – Impedire editing pagine

Aprire blog/wp-content/themes/mytheme/functions.php

Aggiungere le righe:

add_action( 'pre_get_posts' ,'exclude_this_page' );
function exclude_this_page( $query ) {
        if( !is_admin() )
                return $query;
        global $pagenow;
        if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
                $query->set( 'post__not_in', array(10,2,14) ); // array page ids
        return $query;
}
By |Web Design, WordPress|Commenti disabilitati su WordPress – Impedire editing pagine

Corso Base Principianti JQuery OnLine – Richiesta HTTP – $.get()-$.post()

JQuery ci permette di gestire le richieste HTTP GET e POST.

By |JQuery, Web Design|Commenti disabilitati su Corso Base Principianti JQuery OnLine – Richiesta HTTP – $.get()-$.post()

JQuery Corso Base OnLine – Cos’è il Traversing

Una caratteristica degna di nota di JQuery sono i metodi e le funzioni che ci mette a disposizione per effettuare il Traversing del DOM. Traversing lo potremo tradurre come “attraversare e scorrere il DOM (Document Object Model) del documento HTML.

By |JavaScript, Web Design|Commenti disabilitati su JQuery Corso Base OnLine – Cos’è il Traversing