I know there have been many questions like this, but none of them solved my problem. I have a game object with a C# script on it which I am trying to access a public field of from javascript. I am using a function in a javascript file (shown below) to access this script and get the field I want. However, Unity gives me an error saying that the script name that I am looking for is an unknown identifier.
function Move(person : GameObject, target : GameObject) {
person.GetComponent(typeof(AIFollow)).enabled = true;
person.GetComponent(typeof(AIFollow)).target = target;
}
Error: Unknown Identifier: ‘AIFollow’
The person game object, when passed to the function, has the AIFollow script attached. I just want to enable that script and get modify a field of it. Any idea what I am doing wrong?
Thanks,
dylan92
C# and JS can’t see each other at compile time - but once compiled, the CIL code can be accessed by scripts written in any language. Unity compiles scripts in 3 waves, according to the folder the scripts are stored: Standard Assets and Plugins first, their Editor subfolders second, other folders in third place. You can place the C# scripts in Standard Assets, and the JS scripts in some custom Assets folder - like Assets/JsScripts, for instance. This will make C# scripts visible for JS, but not the other way around - only the scripts compiled last can “see” the others.
Is there a more elegant solution than shoving js and c# in different places just for the sake of execution order? Or isn’t it possible to manually specify the folder names and their execution order?
Save GameObject States in a file you want to get in cs or js
Just import this file Js or C# you want