Search Unity

Recognizing Javascript from C# in Visual Studio.

Discussion in 'Scripting' started by acmshar, Jan 19, 2011.

  1. acmshar

    acmshar

    Joined:
    May 4, 2010
    Posts:
    29
    When I am writing in C# to call a function from a file that is in Javascript, I am getting an error in Visual Studio 2010. I have worked around the problem in Unity by ensuring that the Javascript compiles first using the advice on this page. That is, the code runs fine and Unity does what I expect, but Visual Studio keeps telling me there is an error. I have two questions about this:

    Is there a way to get Visual Studio to recognize this is not a problem?

    Is there a better way to do this than stuffing the JS files in Standard Assets?
     
  2. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    You might be able to get around this with some fancy Dependency Injection using run-time reflection to resolve concrete types, but most likely you'd have an easier time simply moving all your code to C#.

    EDIT: Maybe there's a way to have Unity compile a .NET dll of the JavaScript classes which you can then reference in the Visual Studio project, but I have no idea if that's possible.
     
  3. acmshar

    acmshar

    Joined:
    May 4, 2010
    Posts:
    29

    I am planning to do (and already have done) some porting. I just wanted to post to see if there was a simple solution I could use before I get to that.