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

htaccess – BlueHost – cPanel – Directory Password

Protect a Directory with a password using cPanel.

CREATE PROTECTION

1. Enter as administrator into cPanel

2. Security> Directory Password

3. Directory Selection> Web Root> Go

4. Click the Directory you want to protect

5. Check ‘Password protect this directory’
Name the protected directory: give it a name
Save

6. Go Back>
Create User:
Username: give it
Password: give it
Add/Modify Authorized User

Perfect, try to access the files inside the directory, now you need Username and Password

REMOVE PROTECTION

1. Enter as administrator into cPanel

2. Security> Directory Password

3. Directory Selection> Web Root> Go

4. Click the Directory you want to protect

5. Uncheck ‘Password protect this directory’

6. Remove active users if you want

By |Web Design, Web Security|Commenti disabilitati su htaccess – BlueHost – cPanel – Directory Password

JS Redirection – IOS – Android

JS Redirection – IOS – Android

Create in the same folder:
– mobile-detector.html
It this the javascript that detects the device type
– ios.html
The page for IOS devices
– android.html
The page for Android devices
– error.html
An Error page

mobile-detector.html


<!DOCTYPE html>
<html>
<head>
 
<script type="text/javascript">
// #######################################################
// Mobile JS Redirect
// Don't Break My b***s - Gimme Code! Project                                           
// Author: Andrea Tonin - http://blog.lucedigitale.com                                 
// This code come with absolutely no warranty                                            
// If you use this code in your project please give a link to http://blog.lucedigitale.com 
// Thanks in advance                                                                       
// #######################################################
 
var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }

    };



if ( isMobile.Android() ) {
        document.location.href = "android.html";
    }
else if(isMobile.iOS())
	{
	document.location.href="ios.html";
	}
else
    {
    document.location.href="error.html";
    }
 
</script>
 
</head>
 
<body>
<center>
<br>
<b><h1>You are being redirected to other site.</h1>
<br>
<br>
<h1>If you are not redirected within 4 seconds</h1></b>
<br>
<h1><a href="android.html">ANDROID HERE</h1></a>
<h1><a href="ios.html">IOS HERE</h1></a>
</center>
</body>
 
</html>

ios.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
<h1>IOS!</h1>
</body>
 
</html>

android.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
<h1>Android!</h1>
</body>
 
</html>

error.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
You need an Android or IOS device!
</body>
 
</html>

By |JavaScript, Web Design|Commenti disabilitati su JS Redirection – IOS – Android

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

Unity 3D Game Engine – Android – Accelerometer – RAW Data – Translate and Object

Unity 3D Game Engine – Android – Accelerometer – RAW Data – Translate and Object

Inside Hierarchy create:

– Main Camera
– GUI Text X
– GUI Text Y
– GUI Text Z
– Cube (Game Object), attach ‘AccelerometerTest.js’

AccelerometerTest.js


#pragma strict

// Hierarchy DRAG E DROP over var GUI Text in Inspector
var scoreTextX : GUIText;
var scoreTextY : GUIText;
var scoreTextZ : GUIText;

	function Update () {
		var dir : Vector3 = Vector3.zero; // Shorthand for writing Vector3(0, 0, 0)
		
		dir.x = Input.acceleration.x;
		dir.y = Input.acceleration.y;
		dir.z = Input.acceleration.z;
		
		scoreTextX.text = "acceleration.x: "  + dir.x;
		scoreTextY.text = "acceleration.y: "  + dir.y;
		scoreTextZ.text = "acceleration.z: "  + dir.z;
		
	}

Hierarchy> Cube> Inspector> AccelerometerTest.js assign GUI Text to public var scoreText

Here the final result:

dir.x = Input.acceleration.x; from 1 to -1 -> example: 0.1234567 or -0.1234567
dir.y = Input.acceleration.y; from 1 to -1
dir.z = Input.acceleration.z; from 1 to -1

unity-001

unity-002

unity-003

To translate the Cube using Accelerometer data (basic):

AccelerometerTest.js


#pragma strict

function Update () 
{
    transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
}

To translate the Cube using Accelerometer data (advanced):

AccelerometerTest.js


#pragma strict

	// Move object using accelerometer
	var speed = 10.0;

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

	function Update () {
		var dir : Vector3 = Vector3.zero; // Shorthand for writing Vector3(0, 0, 0)
		
		dir.x = Input.acceleration.x;
		
		scoreTextX.text = "acceleration.x: "  + dir.x;
		
		// clamp acceleration vector to unit sphere
		if (dir.sqrMagnitude > 1)
			dir.Normalize();
		
		// Make it move 10 meters per second instead of 10 meters per frame...
		dir *= Time.deltaTime;
			
		// Move object
		transform.Translate (dir * speed);
		
	}

unity-004

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Android – Accelerometer – RAW Data – Translate and Object