- Home /
Calling Javascript Method fron C# NGUI
Requirement: Call a method at the start of the application/game to initialize all my static variables. I have a class called as MyClass.js which has
static function MyFirstCall()
{
/* Game specific Initialization */
return myString;
}
I am using NGUI for my first screen. How do I call this method in MyClass.js from FirstScreen? Currently I am trying to call this in UICamera.cs Awake() method.
Javascript file is under Plugins while NGUI Scripts are under Plugins->NGUI.
Any help would be appreciated.
Answer by rutter · Jun 15, 2012 at 05:28 AM
C# and JavaScript classes can't normally communicate with each other, except if one of them is compiled before the other -- see Unity's script reference page on compilation order. So, you could put one script in the early pass, and another script in the late pass; the script in the late pass will then be able to access fields and methods in the other.
Simpler option: use `SendMessage()` if you can get away with it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072810im_/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
Change value of javascript variable with NGUI button 0 Answers
How to Calling function in JS from C# 1 Answer
how to use matrice with unity 3D 1 Answer