Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 danny83 · Jul 19, 2011 at 09:01 AM · c#yieldienumeratorwwwform

Problem using yield and IEnumerator in a custom function

I am trying to get the following working, with some modifications, and in C#: http://unity3d.com/support/documentation/ScriptReference/WWWForm.html

The code works when its in the Start function, however I would like to load a few files in sequence, so moved the code to its own function, and that's when it stopped working:

     void Start()
     {
         Debug.Log("readPlayerData");
         //StartCoroutine( readPlayerData(dataUrl));
         readPlayerData(dataUrl);
     }
 
     private IEnumerator readPlayerData(string dataUrl)
     {
         string playName = "Player 1";
         int score = -1;
 
         // Create a form object for sending data to the server
         var form = new WWWForm();
         // Assuming the script manages for different games
         form.AddField("game", "MyGameName");
         // The idof the player 
         form.AddField("id", playerObject.myID);
         // The score
         form.AddField("score", score);
 
         // Create a download object
         WWW downloadW = new WWW(dataUrl, form);
 
         // Wait until the download is done
         yield return downloadW;
 
 
         if (downloadW.error != null)
         {
             Debug.Log("Error downloading: " + downloadW.error);
         }
         else
         {
             // show the data
             Debug.Log("DATA: " + downloadW.text);
         }
     }


I would guess it has something to do with the yield and IEnumerator code.. The code runs, but it seems to just stop indefinitely when it gets to the yield, and doesn't even time-out..

Ideally I would like to call the function multiple times using the StartCoroutine, but I think getting the above to work first would be logical.

Maybe its just some basic C# knowledge that I am missing, so any help would be appretiated.

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

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Eric5h5 · Jul 19, 2011 at 09:09 AM

You have to use StartCoroutine in C# or it's just run as a normal function and yields won't work.

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
0

Answer by danny83 · Jul 20, 2011 at 02:25 AM

Ok cheers, that helps, in that case I was having problems using StartCoroutine, anyway its all sorted now, so thank you.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Waiting twice inside coroutine (C#) 2 Answers

Distribute terrain in zones 3 Answers

What am I doing wrong with IEnumerator? 1 Answer

Having trouble refactoring an IEnumerator method with multiple yields 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