- Home /
help using a C sharp class from javascript
I'm having problems with using the Triangulator from the wiki, using javascript. http://www.unifycommunity.com/wiki/index.php?title=Triangulator
I tried to write
var vertices2D:Vector2[]; function Start(){ var vertices2D = [Vector2(0,0), Vector2(0,50), Vector2(50,50), Vector2(50,100), Vector2(0,100), Vector2(0,150), Vector2(150,150), Vector2(150,100), Vector2(100,100), Vector2(100,50), Vector2(150,50), Vector2(150,0)];
var tr = new Triangulator(vertices2D);
var indices:int[] = tr.Triangulate();
var vertices = new Vector3[vertices2D.Length];
for(var i = 0 ;i<vertices.Length;i++){ vertices[i] = Vector3(vertices2D[i].x, vertices2D[i].y, 0); } var msh:Mesh = new Mesh(); msh.vertices = vertices; msh.triangles = indices; msh.RecalculateNormals(); msh.RecalculateBounds();
var newObject:GameObject = new GameObject("newObject"); newObject.AddComponent(MeshFilter); newObject.AddComponent(MeshRenderer);
newObject.GetComponent(MeshFilter).mesh = msh;
}
as an attempt to convert the "PolygonTester" example into javascript, but I get an error with "var tr = new Triangulator(vertices2D):" line. saying:
unknown identifier: triangulator.
should I place the Triangulator c sharp script somewhere special in order for it to work?
Answer by Eric5h5 · Nov 13, 2010 at 10:54 PM
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html (section 4 in particular)
Your answer
![](https://koobas.hobune.stream/wayback/20220613083004im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Initialising List array for use in a custom Editor 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Flip over an object (smooth transition) 3 Answers