Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alberto-lara · Sep 22, 2013 at 06:38 PM · javascriptarrayguitexturetouchscreen

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 :(

alt text

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Arrays vs. XML or SQLite: Fastest data storage/retrieval using JavScript/UnityScript? 0 Answers

Resizing arrays, and what is the default array type anyway? 3 Answers

array out of range in simple pathinder javascript 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges