Touch: works on Unity-Remote, doesn't work on Android device after building

In my Android game I want to use the perspective camera. When the user touches something with a specified name something happens. Using Unity-Remote on my android device everything works well, but when I build the game, the script on my android device doesn’t work (probabily I think the ray isn’t well cast… but I have no idea why!)
Could you kindly help?
This is my script:

private var levelStateMachine : LevelStatus;	// link to script that controls the level.

var cam: Camera;

function Start () {		
	levelStateMachine = FindObjectOfType(LevelStatus);
	if (!levelStateMachine)
		Debug.Log("No link to Level Status");
}

function Update () {
	if(levelStateMachine.touchEnabled){
	// Rileva il tocco
    if((Input.touchCount>0) && (Input.GetTouch(0).phase == TouchPhase.Ended)) {
		var gameObject : GameObject = GetClickedItem(Input.GetTouch(0).position);
		Debug.Log(gameObject.name);
		if(gameObject.name == "Heart") levelStateMachine.heartBeat(1);//levelStateMachine.heartBeat(1); //contatore -1;
			else if(gameObject.name == "FHeart" || gameObject.name == "SHeart") levelStateMachine.heartBeat(3); //contatore -3;
			else if(gameObject.name == "+Heart") levelStateMachine.heartBeat(2); //contatore -2
	}
	}
	
	if(Input.GetKey("up") && levelStateMachine.touchEnabled) {
		levelStateMachine.heartBeat(1);
	}
	
}

// Rileva l'elemento cliccato
function GetClickedItem(pos: Vector2) {
	var camera : Camera = cam; //Camera.main;
	var vektor = Vector3(pos[0],pos[1],0f);
	var hit : RaycastHit;
	var ray : Ray = Camera.main.ScreenPointToRay (vektor);
	if (Physics.Raycast(ray, hit, Mathf.Infinity)) return hit.collider.gameObject;
		else return null;
}


//DEBUG

function OnMouseDown(){
	if(levelStateMachine.touchEnabled){
		if((this.name == "Heart")) levelStateMachine.heartBeat(2);
	}
}

if((Input.touchCount>0) && (Input.GetTouch(0).phase == TouchPhase.Ended))

Id say the above code is the problem.

Acquire the information you want in phase began. You can process it in Ended.

Also, use a different name than gameObject, as this particular name refers to the gameObject the script is attached to.
On top of that, you will need to declare this object Outside of Update loop so it has scope class-wide.

I just overcome the same problem.
The problem was, that I had 2 spots in my code that I did input check. One was in the Update() where I was checking for TouchInputs and I was calling a foo() methods if I detected a touch, and also I had a onMouseDown() methode (because I was developing in a computer ofcource and I wanted to test the game with mouse clicks) that called the same foo() methode. Propably (it is very comon) in a game, a touch does a selection. You tap something to select it, and propably you hav coded already that if you select it again it deselects. So if you have both methodes (touch and mouse) because unity on a mobile translates touches to mouse events, you’ll call foo() twice. So your object will be selected and deselected on an instance and you would think that touch didn’t work. But it did. So check if you have a leftOver OnMouseDown methode somewhere and comment it out before you build. I hope taht helped…