- Home /
Use variabel in other script does not work
hello, I have a main script in c# where there is a public static string gameNumber;
and a js script where I want to use this variabel I use this:
if (ConnectMenu.gameNumber == THREE){
then my code ending with } It used in a function spawn() now, every time I try to play it says
Unknown identifier: 'ConnectMenu'.
Does anybody can help me? I realy want this to work
Answer by belvita · Dec 03, 2013 at 10:50 PM
Try to convert ur java script code to c# code and access gamenumber variable from ur converted c# code.
I'm not judging. Just letting you know..
The problem is, I can't change all of my codes to c#
It's to much work and my knowledge of c# is not that great
(ps flaviusxvii, I'm Belgian, English isn't that good)
Answer by EnglishMuffin123 · Dec 04, 2013 at 09:18 AM
Make sure your C# script with the variable you want to access is placed inside a folder called Plugins inside your assets folder.
Assets >> Plugins >> C# Script
Use getComponent()
to access the script if it's on another GameObject.
I can not replace it or I get an error Is that also possible in the directory: Assets>>FPS>>_Custom Assets>> scripts>> Networkc# ?
What's your error? The problem with converting between c# and javascript is that accessing one language from the other is difficult. To access c# from js, the c# code must be in plugins. To access js from c#, the c# code must be in plugins.
the eroor is about the cs script, other script use it on his current location if i remove it to Plugins most of them won't work and it as to much work to trace the scripts again
Ok, if that's your problem then your only option is to rewrite the script in JavaScript or rewrite the script accessing it in C#. It's unfortunate but these languages are built differently so it's difficult to make them communicate.
Your answer
