Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

WWW in C#

Discussion in 'Scripting' started by RockHound, Oct 13, 2006.

  1. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    In C#, I can use
    Code (csharp):
    1. WWW.GetURL("http://unity3d.com/Documentation/ScriptReference/WWW.html");
    to block execution while retrieving a web page. However, I can't use
    Code (csharp):
    1. WWW("http://unity3d.com/Documentation/ScriptReference/WWW.html");
    to get the web page asynchronously (non-blocking). What is the correct syntax for C#? All the examples in the manual and wiki are in JavaScript.

    Thanks.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  3. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    To create an object in C# you must add the new keyword to the statement, which is optional in Javascript:
    Code (csharp):
    1.  
    2. new WWW("http://unity3d.com/Documentation/ScriptReference/WWW.html");
    3.  
     
  4. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    Thanks for your reply, freyr. When I try "new WWW...," I get the following error message:

    "the type 'UnityEngine.WWW' has no constructors defined"

    So, if WWW is an object, why does it have no constructors, even default? And, if I should use a coroutine here, which function is the coroutine, assuming it is supposed to return an IEnumerator type? (GetURL returns a string)

    I am still pretty new to C# (though I have extensive C++ experience), so I may be misunderstanding the language somewhere. I'd like to solve this problem, and see a working example in C#.

    Thanks for any clarifications!
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You will have to use JavaScript for this one. There is an issue in the bindings which makes the constructor unaccessable from C#. C# bindings will work with Unity 1.6.
     
  6. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    Not a problem. Thanks for the info!