Skip to main content


Showing posts from 2013

How to implement Appirater in unity

Here is a working example of Appirater for unity iphones. I was very noob with objective-c when i first did this. So i combined Appirater example given in this site"" with unity ios Bonjour example and made it to work.

Before building your xcode, open from  Assets/plugin/ios, add your appID and other details like after how many uses you want to promote user to rate your app.
Here is a image showing where you want to add your AppID.

After adding your appID and other details, use this script  to call Appirater.

using UnityEngine; using System.Collections; using System.Runtime.InteropServices;
publicclassCallAppiraterU : MonoBehaviour {
[DllImport ("__Internal")] privatestaticexternvoid_StartLookup(string service, string domain);
// Use this for initialization void Start () {         if (Application.platform == RuntimePlatform.IPhonePlayer)         {                  _StartLookup("_daap._tcp","…

How to ignore Raycast in Unity

Ignoring ray cast is pretty simple, but i saw peoples little confused on this topic, even i got little confused when i first tried this. So i thought to post a blog on this topic.

To ignore ray cast you just need to create a LayerMask variable in inspector. Than select all layers on which you want to cast your ray and leave the layer (unmark) on which you don't want to cast your rays That's it, now all you need to do is include that LayerMask variable in your ray casting.

using UnityEngine; using System.Collections; using System; publicclass Player : MonoBehaviour {
publicCamera myCam; publicLayerMaskignoreLayers;
void Update () { if(Input.GetMouseButtonDown(0))       { RaycastHithit; varray2 = myCam.ScreenPointToRay (Input.mousePosition); if(Physics.Raycast (ray2,out hit,Mathf.Infinity,ignoreLayers))               {                     print(hit.collider.tag);              }       } }
Or you can do it another way,

using UnityEngine; using System.Collections; using System; publicclass Player …

Read and Write XML using csharp in unity

Hi Guys, Here is another post showing how to save position and rotation of players using xml in Unity3d.
Let me describe few things about this small dummy game. There are players you can control by clicking on them and using arrow keys you can move them. There are 2 GUI Buttons, one to save "positions & rotation" and one to Load "positions & rotation".

To save "positions & rotation" I am storing all players into a list of GameObjects, when we press save button, we create nodes in XML file for each player with there names and stores there "positions & rotation" in it.
And when we load data form Xml we check if that player is present in the game world (how ? -by using there names) "?when we saved them we used there names, so this will help us now to first find them and than update there position and rotation".

Here is a video..

This is the xml we will get after we click the save button.
<?xml version="1.0"e…

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 =;
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…

Best Homing Missile in Unity

Today I finally found the best homing missile solution that i was searching for a long time. Since i like to collect good things, that is why i am posting this script here, in my blog.  Thanks to JamesLeeNZfor providing such a awesome script.

Here is the unity forum link.

#pragma strict
var _velocity : float = 10;
var _torque: float = 5;
var _target : Transform;
var _rigidbody : Rigidbody;

function Start()
           _rigidbody = transform.rigidbody;

function Fire()
var distance = Mathf.Infinity;
for (var go : GameObjectinGameObject.FindGameObjectsWithTag("Enemy"))
var diff = (go.transform.position - transform.position).sqrMagnitude;    if(diff < distance)                     {
                             distance = diff;
                            _target =  go.transform;

function FixedUpdate()
if(_target == null || _rigi…

Unity Joystick.cs

Here is the conversion of Unity Joystick.js ( Javascript ) to Joystick.cs (csharp). I too found the solution on the internet but i am re-posting this because i found this solution after searching a lot and trying lots of non working solutions.
I used this script with Unity 4.1 ios and its working very well and exactly as Unity Joystick.js.

Here is the Original link where i found the solution thanks to him.

using UnityEngine;    [RequireComponent(typeof(GUITexture))]  publicclass Joystick : MonoBehaviour { 

class Boundary {  publicVector2 min =;  publicVector2 max =;  }  

privatestaticJoystick[] joysticks;

// A static collection of all joysticks privatestaticbool enumeratedJoysticks = false;

privatestaticfloat tapTimeDelta = 0.3f;

// Time allowed between taps publicbool touchPad;

publicVector2 position =;

publicRect touchZone;

publicVector2 deadZone =;

// Control when position is outp…