- Home /
Using JS class in C#
Hello all, I have a class in a JS file called LevelSlice that is defined explicitly:
class LevelSlice { private var state:int; ...
function LevelSlice(){
...
}
}
And I have a C# script level01.cs:
using UnityEngine; using System.Collections;
public class level01 : MonoBehaviour { LevelSlice levelSlice;
void Update () {
...
}
}
and I get the error: error CS0246: The type or namespace name `LevelSlice' could not be found. Are you missing a using directive or an assembly reference?
I have read the documentation but it seems that that applies only to JS classes trying to access C# classes. Is this correct? I've written about 1/3 of my code for this project in JS and I need C# for this single script, so I'm not really keen on rewriting all my code in C#.
Any help will be much appreciated
Thank you
-Steve
Answer by Mike 3 · Apr 03, 2011 at 06:48 AM
Nope, both way works fine, the issue is compilation order.
Put the js script in question in Standard Assets or Plugins, and the c# script anywhere but those, and it should be able to see it.
Be aware that you'll then need to move any js file that the first js file depends on too.
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html
why does everyone keep referring to this page that does not exist?