Skip to main content

Posts

Showing posts from October, 2013

How to detect Double Tap on touch devices using unity

So here is a working double tab detection script, logic behind double tap is very simple, you can detect double tap when Input.GetTouch(i).tapCount get equals to 2.

#pragma strict
function Update ()  { for (var i = 0; i < Input.touchCount; ++i)
       { if (Input.GetTouch(i).phase == TouchPhase.Began)                 { if(Input.GetTouch(i).tapCount == 2)                         { // double tap :)                         }                }        }
}


How to move in a circular path in unity

This script moves your character in a circular path. To test this script, Create a Capsule with a character controller, add this script to your Capsule. Create a cube or any game Object and put it in a distance from the Capsule (that distance is your radius) now drag that game Object to target variable in Inspector. now play the game and press right/left keys to move in a circular path. 

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0; var target : Transform; privatevar moveDirection : Vector3 = Vector3.zero;
function Update() { var controller : CharacterController = GetComponent(CharacterController);         moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0); var worldLookDirection = target.position - transform.position; var localLookDirection = transform.InverseTransformDirection(worldLookDirection);         localLookDirection.y = 0;         transform.forward = transform.rotation * localLookDirection;         moveDirection = transform.Transfo…