- Home /
Access JS From C#
I have read up on this for most of the afternoon but i cannot for the life off me get it too work.
I am trying too access some scripts that are in JS from my main code base which is C#.
I have all of the JS files inside the plugins folder (Also tried Standard Assets) but i cannot even access the class to be able to access its methods or variables.
Inside the settings i have also changed the script compilation order for the 4 scripts i need to access and gave them a value representing something like this ----- > script 1 -200 script 2 -100 script 3 -80 script 4 -40.
I have no idea why it is not working can anyone help?
Thank you for taking the time to read this.
Cheers
John
To access JS from C# you will need to put the C# in the standard assets folder not the JS.
Hows that the case though when C# is compiled before JS?
Answer by orcunguducu · Nov 07, 2014 at 01:18 PM
Make sure your scripts are static or have a instance to access?
Ah no there is an instance of them as they are on an object in my scene. :(
It is not enough to be in scene to reach that script. You need an instance.
Can you try this:
public class YourClassName: $$anonymous$$onoBehaviour
{
public static YourClassName Instance;
void Awake() {
Instance = this;
}
void HelloFunction() {
//Bla bla
}
}
public class AnotherClassName: $$anonymous$$onoBehaviour
{
void Start() {
YourClassName.Instance.HelloFunction();
//you are accessing YourClassName with static Instance
}
}