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 /
This question was closed Oct 15, 2013 at 08:15 AM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Michael S · Oct 03, 2013 at 01:46 PM · c#arrayguitextphp

C# Array, GuiText, assign strings.

Hi,

Im getting an array from a PHP script from my server with 11 strings.

I have an array with 11 gameobject(with GUIText on them) and i want to assign the strings to the gameobjects.

So that the Guitext show the string info.

like Array_GameObjects[i] = Array_php[i];

C#

Kind Regards

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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Michael S · Oct 15, 2013 at 08:14 AM

I changed the code to this, and it works :)

 IEnumerator GetData(WWW w)
     {
         if(Loading == true)
         {
             guiLoading.guiText.text = "Loading Data";
         }
         else if (Loading == false)
         {
             guiLoading.guiText.text = "";
         }        
 
         
 
         if (w.error != null)
         {
             print("There was an error getting the high score: " + w.error);
         }
 
         else
         {
             Loading = false;
             
 
             RegexOptions options = RegexOptions.None;
             Regex regex = new Regex(@"((""((?<token>.*?)()"")|(?<token>[^&&]+))(\s)*)", options);
             string input = w.text;
             var result = (from Match m in regex.Matches(input)
                           where m.Groups["token"].Success
                           select m.Groups["token"].Value).ToList();
             int pos = 0;
             for (int i = 0; i < result.Count(); i += 2, pos++)
             {                                   
                 GameObject currentGuiText = Instantiate(GuiPrefab, new Vector3(0,0,0), Quaternion.identity) as GameObject;
                 
                 _list.Add(currentGuiText);
 
                 result[pos] = result[i];
             }
             result.RemoveRange(pos, result.Count - pos);
             Debug.Log("result" +result.Count);
             Debug.Log("list" + _list.Count);
             for (int i = 0; i < result.Count(); i++)
             {
                 _list[i].guiText.text = string.Format("{1}", i, result[i]);
                 
                 Loading = false;
 
 
             }
 
 
         }
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
avatar image
1

Answer by KiraSensei · Oct 03, 2013 at 01:55 PM

Here is the doc about GUIText.

if Array_GameObjects contains GUIText game objects, you need to access their text to change it. Try something like that :

 GUIText myCurrText = Array_GameObjects[i];
 myCurrText.text = Array_php[i];

Comment
Add comment · Show 1 · 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
avatar image Michael S · Oct 08, 2013 at 08:41 AM 0
Share

I tried this:

 IEnumerator GetData(WWW w)
     {
 
         info[0].guiText.text = "Loading Data";
      
          yield return w;
      
         if (w.error != null)
         {
             print("There was an error getting the high    score: " + w.error);
         }
 
         else
         {
             string[] InfoResult = Regex.Split(w.text, "-");

             foreach (string entry in InfoResult)
             {
 
                 string[] TextData = entry.Split( '-' );
               
             int phpStringLength = info.Length - 1;
                 for (int i = 0; i <= phpStringLength; i ++ )
                 {
                    
                     info[i].guiText.text = TextData[i];
 
                 }
             
         }
 
             info[0].guiText.text = w.text;
             info[1].guiText.text = w.text;
             info[2].guiText.text = w.text;
             info[3].guiText.text = w.text;
             info[4].guiText.text = w.text;
             info[5].guiText.text = w.text;
             info[6].guiText.text = w.text;
             info[7].guiText.text = w.text;
             info[8].guiText.text = w.text;
             info[9].guiText.text = w.text;
             info[10].guiText.text = w.text;
         }
     }

But i get This Error : IndexOutOfRangeException: Array index is out of range. WWWController+c__Iterator1.$$anonymous$$oveNext () (at Assets/Scripts/WWWController.cs:104)

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

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Array index help. 1 Answer

Playing a soundclip at random from an array. C# 2 Answers

create string array from xml 2 Answers


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