I’m not familiar with C#.
I think I’m just write something wrong here. An Object with an JS-script attached has the static String variable: myString.
Another Object, with an C#-script attached needs to access myString in the JS-script.
in my C#-script:
GameObject.Find(“MyObject”).GetComponent(“the_name_of_the_JSscript”).myString = “some string”;
i get the error:
error CS1061: Type UnityEngine.Component' does not contain a definition for some string’ and no extension method some string' of type UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)
It seems to find the Object and also the Script-Component. But it doesn’t find the variable. No matter if it’s static or public.
thanks for help!
In C# you do not use the brackets the same way you do in JS.
Try:
GameObject.Find(“MyObject”).GetComponent<“the_name _of_the_JSscript”>().myString = “some string”;
I am not familiar with C# either, but as far as i remember, this is how you’d do it.
Hope it helps, good luck!
thank you, Ted.
I’m not quite there, but it doesn’t look so bad anymore. I just get the error: error CS1525: Unexpected symbol `)’
I tried out some other notations, but I can’t figure it out.
GameObject.Find(“MyObject”).GetComponent().myString = “some string”;
thanks guys! I took me a while to figure it out. But it’s quite easy, actually.
just to recap:
The JS-script must be in the Standard Assets folder (for compiling order reasons) and the script name is without quotation marks.
GameObject.Find(“MyObject”).GetComponent().myString = “some string”;