How to call a c-sharp function from javascript?

Ok, the problem is i need to implement socket connections, but there i think there is no other way than implementing them on c sharp. But now i need to call the functions on my csharp file from javascript and it gives me a compile error, because it cannot find the function in chsarp file. It might be an issue related to compilation order. Can anyone suggest any solutions?

Let's go through the quick check to make sure all of these statements are true:

  1. Unity can find the class. If you get an error that your type doesn't exist, then you may have typed it in wrong or you might have a compilation order problem. SEE below.

  2. You are accessing the function correctly: `instance.Method()` or `ClassName.StaticMethod()`

  3. You typed the method name in correctly (I know its obvious but its worth asking)

If none of these are true you might have an issue with compilation order.

See this page on what order scripts are compiled in. You really just need the C# script to be compiled before the js script. I would suggest either placing it in a "Plugins" folder or in "Standard Assets".

There is also a chance that you can compile them at the same level. There is no specific order that they will be compiled in, but I find often that C# scripts are compiled before js scripts on the same level. Note: That is by no means a guarantee that it will happen that way and you CANNOT rely on this random chance. I am merely stating what I observe more often than not