- Home /
Issue with some GUITextures and an Array [SOLVED]
Hi everyone, in advance, sorry for the bad English. The title doesn't really say much about my problem, it's a little complicated to explain:
The issue is this, I have a group of GUITextures (six) that I can drag with my finger in a touch device, that works fine in the android emulator, the problem is that I want to store de name of the accion in a simple javascript Array (which has a determinated size of 4), but that only works for the accion number one (accion1). In a little more graphic explanation, the 4 empty circles represent the empty Array, it initialized with "(vacio)" in each position, when I drag the textures to the circles, the ControlAcciones.js script must send to the array the name of the object (accion1, accion2... accion6) but it ONLY WORKS WITH THE accion1 TEXTURE :(
I left the ControlAcciones.js script:
#pragma strict
var letrero:GUIText;
private var accion:GUITexture;
private var esferas_accion:GameObject[];
private var seleccionada=false;
private var acciones_listas=new Array();
function Start()
{
accion=gameObject.guiTexture;
letrero.text="";
//Get the action_spheres (1,2,3 and 4):
esferas_accion=GameObject.FindGameObjectsWithTag("EsferaDeAccion");
//They're disordered, I ordered here (redundant usage of methods, I know)
for(var i=0;i<esferas_accion.length;i++)
{
esferas_accion[i]=GameObject.Find("action_sphere_"+(i+1));
acciones_listas[i]="(vacio)";//Initialize positions.
}
print(accion.name);
}
function Update()
{
for(var t:Touch in Input.touches)
{
switch(t.phase)
{
case TouchPhase.Began://Drop finger.
if(accion.HitTest(t.position))
{
seleccionada=true;
//Zoom and center guitexture:
var factor=accion.pixelInset.width/3;
var _x=accion.pixelInset.x;
var y=accion.pixelInset.y;
var an=accion.pixelInset.width;
var al=accion.pixelInset.height;
accion.pixelInset=Rect(_x,y,an+factor,al+factor);
accion.pixelInset.x=t.position.x-accion.pixelInset.width/2;
accion.pixelInset.y=t.position.y-accion.pixelInset.height/2;
}
else
seleccionada=false;
break;
case TouchPhase.Moved://Drag finger:
if(seleccionada)
{
var b=false;
//Center:
accion.pixelInset.x=t.position.x-accion.pixelInset.width/2;
accion.pixelInset.y=t.position.y-accion.pixelInset.height/2;
//If accion is over an action_sphere, let says true:
for(var n=0;n<esferas_accion.length;n++)
if(accion.HitTest(Camera.main.WorldToScreenPoint(
esferas_accion[n].transform.position)))
b=true;
letrero.text=(b)?"true":"false";
}
break;
case TouchPhase.Ended://Lift the finger:
seleccionada=false;
letrero.text="";
//Verify if accion is over an action_sphere:
for(var i=0;i<esferas_accion.length;i++)
{
//This only works with accion1 :(
if(accion.HitTest(Camera.main.WorldToScreenPoint(
esferas_accion[i].transform.position)))
{
letrero.text=accion.name+" is on "+(i+1)+"\n";
acciones_listas[i]=accion.name;
}
}
//Print the array acciones_listas to the let GUIText:
for(i=0;i<acciones_listas.length;i++)
letrero.text+=acciones_listas[i]+" ";
//Return accion to the original position:
var x=-1;
for(i=0;i<6;i++)
if(accion.name=="accion"+(i+1))
x=i*50;
accion.pixelInset=Rect(x,0,35,35);
break;
}
}
}
And here's the whole proyect: https://www.dropbox.com/s/h3t5uq0h5ffg47b/test_game.unitypackage Many thanks for your help, I have more than a week with this and I'm a little desperate :s
Answer by alberto-lara · Sep 24, 2013 at 06:46 AM
Apparently, the problem was that I have 'acciones_listas' in the six actions, so I have many lists (when I only need one). Anyway, thank you very much.