programming

Unity 3D – Stealth Game – Player Movement – JS Script

Unity 3D – Stealth Game – Player Movement – JS Script

Select the player object and assign:

PlayerMovement.js

#pragma strict

public var shoutingClip : AudioClip;        // Audio clip of the player shouting.
public var turnSmoothing : float = 15f;     // A smoothing value for turning the player.
public var speedDampTime : float = 0.1f;    // The damping for the speed parameter


private var anim : Animator;                // Reference to the animator component.
private var hash : HashIDs;                 // Reference to the HashIDs.


function Awake ()
{
    // Setting up the references.
    anim = GetComponent(Animator);
    hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent(HashIDs);
    
    // Set the weight of the shouting layer to 1.
    anim.SetLayerWeight(1, 1f);
}


function FixedUpdate ()
{
    // Cache the inputs.
    var h : float = Input.GetAxis("Horizontal");
    var v : float = Input.GetAxis("Vertical");
    var sneak : boolean = Input.GetButton("Sneak");
    
    MovementManagement(h, v, sneak);
}


function Update ()
{
    // Cache the attention attracting input.
    var shout : boolean = Input.GetButtonDown("Attract");
    
    // Set the animator shouting parameter.
    anim.SetBool(hash.shoutingBool, shout);
    
    AudioManagement(shout);
}


function MovementManagement (horizontal : float, vertical : float, sneaking : boolean)
{
    // Set the sneaking parameter to the sneak input.
    anim.SetBool(hash.sneakingBool, sneaking);
    
    // If there is some axis input...
    if(horizontal != 0f || vertical != 0f)
    {
        // ... set the players rotation and set the speed parameter to 5.5f.
        Rotating(horizontal, vertical);
        anim.SetFloat(hash.speedFloat, 5.5f, speedDampTime, Time.deltaTime);
    }
    else
        // Otherwise set the speed parameter to 0.
        anim.SetFloat(hash.speedFloat, 0);
}


function Rotating (horizontal : float, vertical : float)
{
    // Create a new vector of the horizontal and vertical inputs.
    var targetDirection : Vector3 = new Vector3(horizontal, 0f, vertical);
    
    // Create a rotation based on this new vector assuming that up is the global y axis.
    var targetRotation : Quaternion = Quaternion.LookRotation(targetDirection, Vector3.up);
    
    // Create a rotation that is an increment closer to the target rotation from the player's rotation.
    var newRotation : Quaternion = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
    
    // Change the players rotation to this new rotation.
    rigidbody.MoveRotation(newRotation);
}


function AudioManagement (shout : boolean)
{
    // If the player is currently in the run state...
    if(anim.GetCurrentAnimatorStateInfo(0).nameHash == hash.locomotionState)
    {
        // ... and if the footsteps are not playing...
        if(!audio.isPlaying)
            // ... play them.
            audio.Play();
    }
    else
        // Otherwise stop the footsteps.
        audio.Stop();
    
    // If the shout input has been pressed...
    if(shout)
        // ... play the shouting clip where we are.
        AudioSource.PlayClipAtPoint(shoutingClip, transform.position);
}
By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D – Stealth Game – Player Movement – JS Script

Unity – Performance Test

Unity – Performance Test

Sometimes you need a benchmarks and system performance tests.

1. File> Open Project…> open your project
2. MAIN TOP MENU> Window> Profiler
3. MAIN TOP Play button to run the game

Now you can see inside Profiler Window:
– CPU Usage
– GPU Usage
– Rendering
– Memory
– Audio
– Physics
– Physics (2D)

By |Unity3D, Video Games Development|Commenti disabilitati su Unity – Performance Test

Unity 2D – Sprite Sheet Animation

Unity 2D – Sprite Sheet Animation

‘SpriteSheet’ is a larger image for combining multiple individual images into a single, efficiently laid out image.

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 2D – Sprite Sheet Animation

Unity – Folders organization

Unity – Folders organization

Default Unity install path

C:\Programmi\Unity\

Asset Store

C:\Utenti\YouUserName\AppData\Roaming\Unity\Asset Store\PublisherName

\Particle Systems
\3D ModelsEnvironmentsLandscapes
\Complete ProjectsTemplates

Format sample: Cartoon FX Pack.unitypackage

By |Unity3D, Video Games Development|Commenti disabilitati su Unity – Folders organization

MySQL Quick Reference – NULL

NULL Values

NULL values represent missing unknown data.
By default, a table column can hold NULL values.
It is not possible to compare NULL and 0; they are not equivalent.

To select NULL Values:

SELECT LastName,FirstName,Address FROM Persons
WHERE Address IS NULL

MySQL does have an ISNULL() function. However, it works a little bit different from Microsoft’s ISNULL() function.
In MySQL we can use the IFNULL() function, like this:

SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))
FROM Products

OR

SELECT ProductName,UnitPrice*(UnitsInStock+COALESCE(UnitsOnOrder,0))
FROM Products

To select only the records with no NULL values:

SELECT LastName,FirstName,Address FROM Persons
WHERE Address IS NOT NULL
By |MySQL, Web Design|Commenti disabilitati su MySQL Quick Reference – NULL