Search Unity

JavaScript.Array -> C#.List and constructor

Discussion in 'Scripting' started by Vizzart, Jul 28, 2009.

  1. Vizzart

    Vizzart

    Joined:
    Jul 28, 2009
    Posts:
    4
    Hi Folks!

    Time to join this great community. I started working with Unity a couple of weeks ago and was able to find help and tips for any question i had in the forums and wiki.
    But now i could need some advice:

    I'm trying to invoke the Triangulation-Script from rune in my JavaScript.
    In this Script i've got an Array of 2D vertices but i fail passing this Array to the Triangulation.cs.

    I tried a couple of things. This is what i got right now.

    Code (csharp):
    1.  
    2. var triangulator : Triangulator = GetComponent("Triangulator");
    3. temp = new Triangulator(vertices2D);
    4. temp.Triangulate();
    5.  
    This one throws error: "type "Triangulator" does not have a visible constructor that matches the argument list (Array)"

    Thing is, i dont even know if i call the C# right.

    The Triangulator.cs constructor awaits this:

    Code (csharp):
    1.  
    2. public Triangulator (Vector2[] points) {
    3.     m_points = new List<Vector2>(points);
    4. }
    5.  
    I'm not that familiar with C# so .. i could really need a push in the right direction.

    Cheers
    Vizzart
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    The C# script expects a built-in array. Try:
    Code (csharp):
    1.  
    2. temp = new Triangulator(vertices2D.ToBuiltin(Vector2));
    3.  
    For more detailed info:
    http://unity3d.com/support/documentation/ScriptReference/Array.html
     
  3. Vizzart

    Vizzart

    Joined:
    Jul 28, 2009
    Posts:
    4
    Works like a charm. Thanks a lot!

    (And its even in the docs! Doh!)