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();
}
}