unity3d

Unity 3D Game Engine – Android – Native Camera Access

Unity 3D Game Engine – Android – Native Camera Access

Inside Hierarchy create the scene with:

1. Main Camera

2. Plane in front of the Camera, attach the script ‘GetcameraImg.js’

GetcameraImg.js


// Starts the default camera and assigns the texture to the current renderer
function Start () {
	var webcamTexture : WebCamTexture = WebCamTexture(); // assign the webcam source to var
	renderer.material.mainTexture = webcamTexture;       // render over material texture webcam source
	webcamTexture.Play();	                             // Play the webcam		
}

function Update () {
   
}

3. You can flip, mirror, rotate the 3D Plane to flip, mirror, rotate the webcam texture!

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Android – Native Camera Access

Unity 3D Game Engine – Get Screenshot – Android

Unity 3D Game Engine – Get Screenshot – Android

How to get a in-game Screenshot with Unity 3D – UNTESTED

IMPORTANT!!!

Unity> MAIN TOP MENU> File> Build Settings> Player Settings…> Other Settings> Configuration> Write Access> External (SD Card), this setup will create inside Android Device using Windows 7 -> Phone/Android/data/com.Company.LuceDigitale

It this equal the write inside AndroidManifest.xml ->

Method 1

Application.CaptureScreenshot

NOTICE: CaptureScreenshot is asynchronous. This is because capturing and saving the screen can take awhile.

Inside Hierarchy create a structure with:

1. Some Objects

2. Main Camera, attach the script ‘GetScreenShot.js’

GetScreenShot.js


#pragma strict

// For Android Devices ONLY
// Attach this script to Main Camera

// File> Build Settings> Player Settings...> Other Settings> Configuration> Write Access> External (SD Card),
// this setup will create inside Android Device using Windows 7 -> Phone/Android/data/com.Company.LuceDigitale
// It this equal the write inside AndroidManifest.xml ->  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

var scoreTextX : GUIText;
var localize   : String;

function Start() {
}

function OnGUI()
{
  if (GUI.Button(Rect(10,10,200,50),"Capture Screenshot"))
  { 
    // debug data path
    localize = Application.persistentDataPath;
    scoreTextX.text = localize;
    // it writes:  /storage/sdcard0/Android/data/<bundle id>/files folder
    
    // We should only read the screen buffer after rendering is complete
    yield WaitForEndOfFrame();
    
    // Application.dataPath DOES NOT have write permission on Android, you need Application.persistentDataPath
    // static function CaptureScreenshot(filename: string, superSize: int = 0): void;
    Application.CaptureScreenshot("Screenshot.png");
    // the file will be saved on: /storage/sdcard0/Android/data/<bundle id>/files folder
  }
}

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Get Screenshot – Android

How to get GPS coordinates in Unity 3D

How to get GPS coordinates in Unity 3D

Inside Hierarchy create a scene with:

1. GUI Texture
2. Main Camera, attach the script ‘GetGpsCoord.js’

GetGpsCoord.js


#pragma strict

// Hierarchy DRAG E DROP over var GUI Text in Inspector
var scoreTextX : GUIText;
var localize   : String;

function Start () {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            return;
        // Start service before querying location
        Input.location.Start ();
        // Wait until service initializes
        var maxWait : int = 20;
        while (Input.location.status
               == LocationServiceStatus.Initializing && maxWait > 0) {
            yield WaitForSeconds (1);
            maxWait--;
        }
        // Service didn't initialize in 20 seconds
        if (maxWait < 1) {
            print ("Timed out");
            return;
        }
        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed) {
            print ("Unable to determine device location");
            return;
        }
        // Access granted and location value could be retrieved
        else {
        localize = Input.location.lastData.latitude + " " +
                   Input.location.lastData.longitude + " " +
                   Input.location.lastData.altitude + " " +
                   Input.location.lastData.horizontalAccuracy + " " +
                   Input.location.lastData.timestamp;
                                      
                   scoreTextX.text = "GPS coordinates "+localize;
        }
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop ();
    }

Hierarchy> Main Camera> GetGpsCoord.js> DRAG AND DROP GUI Texture over var scoreTextX

The final result is:

45.04529 -> latitude
11.72339 -> longitude
0 -> altitude
2099 -> horizontalAccuracy
1396651772.795 -> timestamp

By |Unity3D, Video Games Development|Commenti disabilitati su How to get GPS coordinates in Unity 3D

Unity 3D Game Engine – How to make an android device vibrate

Unity 3D Game Engine – How to make an android device vibrate

1. Hierarchy> Main Camera> attach the script ‘Vibrate.js’

Vibrate.js


function Update () {
   
}

// Press button to vibrate START
function OnGUI () {
	if (GUI.Button (Rect (0, 10, 100, 32), "Vibrate!"))
	Handheld.Vibrate ();
}
// Press button to vibrate END

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – How to make an android device vibrate

Unity 3D Game Engine – be or not be kinematic

Unity 3D Game Engine – be or not be kinematic, this is the problem…

When we will create a pick up game object, do we need a kinematic or a non-kinematic object?

PickUp Object

1. Create a Cube (PickUp) as ‘Prefab’ to easy duplicate it, with:

SOLUZIONE 1: senza ‘Rigid Body’, lo considera un ‘Collider Statico’, come un muro, e quindi calcola e salva in cache la posizione una volta per tutte, questo ha senso per risparmiare calcoli in caso di un oggetto che non si muove. Se il nostro cubo ruota Unity salva in cache ogni volta la nuova posizione per ogni frame occupando risorse di sistema.
– Box Collider -> check ‘Is Trigger’ -> così non si effettuano calcoli fisici perchè il ‘Trigger’ rileva solo le collisioni senza causare reazioni fisiche

OPPURE

SOLUZIONE 2: applicando un ‘Rigid Body’, lo considera un Collider dinamico, e non salverà dati in cache, occupando meno risorse.
a. Rigid Body> Disabilitare ‘Use Gravity’ per non far cadere l’oggetto. L’oggetto risponde ancora alle sollecitazioni provenienti da altri Collider.
b. Rigid Body> Abilitare ‘Is Kinematic’ per non far calcolare a Unity le reazioni alle sollecitazioni provenienti da altri Collider e ottimizzare il consumo di CPU. Un oggetto ‘Is Kinematic’ può essere spostato utilizzando la funzione ‘Transform’. Questo setup è tipico delle piattaforme mobili di un videogioco ‘platform’.

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – be or not be kinematic