Raycasting freezes the Android device?

Hello, guys, I was having issues with this bit of code:

    var ray;
	var hit : RaycastHit;
	var obj : infoLibro;
	var vektor : Vector3;
	if(Input.touches.Length > 0) {
		vektor = Vector3(Input.GetTouch(0).position.x,Input.GetTouch(0).position.y,0f);
		ray = Camera.main.ScreenPointToRay (vektor);
		if(Physics.Raycast(ray, hit, 100)) {
			if(hit.transform.gameObject.tag == "libro") {
				nameObj = hit.collider.gameObject.name;
				hRay = true;
				obj = hit.transform.gameObject.GetComponent("infoLibro");
				obj.HoverIn();
				
			}
		} else {
			obj.HoverOut();
			hRay = false;
			nameObj = "";
		}
		if(Input.GetTouch(0).tapCount == 2 && Physics.Raycast(ray, hit, 100)) if(hit.transform.gameObject.tag == "libro") obj.Click();
	} else {
		obj.HoverOut();
	}

This script calls other functions belonging to components in the gameObject it’s calling (HoverIn(), HoverOut() and Click()). It runs OK in PC using Remote, but when I do this in the very Android device the game freezes and crashes itself.

I imagined like there was a problem with the performance pertaining to Physics.Raycast(), but I also take in mind that the object type this snippet is calling (those with the “libro” tag) are around 3000 in total. They all have the same script in them (infoLibro).

I’m also including the code for those functions it’s calling:

function HoverIn () {
	
	shaderAnterior = renderer.material.shader;
	if(esHueco) colorAnterior = Color.white;
	ratonEncima = true;
	//renderer.material.shader = Shader.Find("Unlit/Texture");
	scriptInput.objetivo = gameObject;
	scriptInput.objActivo = true;
	
	if(scriptInput.estanteria) {
		
		if(esHueco) {
			renderer.material.color = Color.blue;
			scriptEst.hueco = gameObject;
		}
	}
}

function HoverOut () {
	
	ratonEncima = false;
	/*
	if(!esHueco) renderer.material.shader = shaderAnterior;
	else {
		renderer.material.shader = shaderAnterior;
		renderer.material.color = colorAnterior;
	}*/
	activaEncima = false;
	scriptInput.objetivo = null;
	scriptInput.objActivo = false;
}

function Click () {
	scriptWatcher = GameObject.Find("watcher").GetComponent(librosWatcher);
	scriptPila = GameObject.Find("zonaPila").GetComponent(scriptZonaPila);
	shaderAnterior = renderer.material.shader;
	if(esHueco) colorAnterior = Color.white;
	ratonEncima = true;
	//renderer.material.shader = Shader.Find("Unlit/Texture");
	scriptInput.objetivo = gameObject;
	scriptInput.objActivo = true;
	
	if(scriptInput.estanteria) {
		
		if(esHueco) {
			renderer.material.color = Color.blue;
			scriptEst.hueco = gameObject;
		}
	}
	
	var camaraActiva : GameObject;
	camaraActiva = GameObject.Find("renderTexCam");
	//if(Input.GetButton("Fire1") && ratonEncima && esPila && scriptPila.dentro1) {
	if(esPila) {
			//scriptWatcher.DestruirLibro(scriptWatcher.idLibroActual);
			scriptWatcher.librosEstado[scriptWatcher.idLibroActual] = 1;
			scriptZonaPila.libroEnMano = scriptWatcher.libro[scriptWatcher.idLibroActual];
			scriptZonaPila.libroEnMano.Destroy(rigidbody);
			scriptZonaPila.libroEnMano.transform.position = GameObject.Find("Bone04").transform.position;
			scriptZonaPila.libroEnMano.transform.rotation = GameObject.Find("Bone04").transform.rotation;
			scriptZonaPila.libroEnMano.transform.parent = GameObject.Find("Bone04").transform;
			var pipi : infoLibro = scriptZonaPila.libroEnMano.GetComponent(infoLibro);
    		scriptZonaPila.libroEnMano.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
			//scriptZonaPila.libroEnMano.collider.enabled = false;
			//libroScript = libroEnMano.GetComponent("infoLibro");
	}
	
	if(esHueco) {
		scriptEst = GameObject.Find(receptorEs).GetComponent(triggerEstanteria); //hAhahHAhaHAaAhaAHhaAahAHaHAhhAHahHAhaHAaHAHahAhaAhaHAahAhaHAAHahAHahAHhah
		activaEncima = true;
	}
	
	if(esHueco) {
		//print("Ahmed");
		if(activaEncima) scriptEst.ComprobarLibro();
	}
}

You have some major issues with you implementation. First, the reason it runs fine on PC is because nothing under the if(Input.touches.Length > 0) will be called. Unless you have a touch monitor. The only place you set obj is here:

obj = hit.transform.gameObject.GetComponent("infoLibro");

so all of your obj.HoverOut(); calls will be throwing a nullReference Exception. If you are doing this 3000 times a frame that could be the issue.

So I realized something was wrong: the raycast script needed to be on the user GameObject, not on the books.

But still, I get the crash on the device, maybe because of the rendering lag included in the CPU consumption. I tried changing the Occlusion mode to PVS, but I still get a lot of Overhead lag.