Monday, 25 November 2013

Basic tutorial for Unity android game development.

1)Back key event

function Update(){

    if ( Application.platform == RuntimePlatform.Android ){
     
     if (Input.GetKey(KeyCode.Escape)){
      Application.Quit();
     }
    }
 
}
2) Object touch event
function Update () {
 TapSelected();
}
function TapSelected() {
  
 for ( var touch : Touch in Input.touches) {

   if (touch.phase == TouchPhase.Began) {
    var ray : Ray = Camera.main.ScreenPointToRay(touch.position);
    var hit : RaycastHit;
    if (Physics.Raycast(ray, hit)) {
    print("selected");
           
      
      hit.transform.SendMessage("Selected");
    }else{
     print("unselected");
    }
   }
 }
}
3) LookAtCamera.js
.js
var whoToLookAt : Transform;
var smoothTime : float = 0.3;
private var yVelocity = 0.0;
var distanceAbove: float = 0.4;
var distanceAway = -1;

function LateUpdate( ) {
    /* transform the camera so it is a distance away from target */
   transform.position = whoToLookAt.position + Vector3(0, distanceAbove, distanceAway);

    /* Look at the target */
    //transform.LookAt( whoToLookAt );
}  /* LateUpdate */

1 comment:

  1. Excellent information, thanks for sharing great information. We deal with Android Game Development this information is quite unique and interesting.

    ReplyDelete