Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

How do I use a mono class from JavaScript?

Discussion in 'Scripting' started by podperson, May 2, 2007.

  1. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Suppose I want to do something like this:

    var sw : StreamWriter = new StreamWrite("foo.txt");

    StreamWriter being System.IO.StreamWriter from .NET
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,778
    At the top of the script put:

    import System.IO.StreamWriter;
     
  3. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Thank you!

    If I import System.IO do I get StreamWriter et al?
     
  4. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Importing just allows shorthand...you could write System.IO.StreamWriter at any time, but by using the import keyword you tell the compiler to check those places for classes that aren't found.

    So you can do import System.IO and then use StreamWriter shorthand (it'll automatically look for StreamWriter in System.IO).