- Home /
get component javascript from a c# script
i have a c# script as my main script.. while clicking mouse i like to access a function from my another script created in java script......... is it possible if yes then how?
thanks in advance
Answer by alberthci · Apr 12, 2011 at 02:17 PM
http://www.41post.com/1935/programming/unity3d-js-cs-or-cs-js-access
...The script you want to have access must be inside the "Standard Assets" or the "Plugins" folder. The other script has to be placed outside these folders. After this step, just call the GetComponent<...>() method as any other Component...
Answer by Steven-Walker · Mar 10, 2011 at 06:40 PM
Scripts are class objects. Javascript files automatically inherit from MonoBehaviour unless otherwise declared, with the name of the file as the class name.
So for example, if you have a script named GameController.js, you can create instances of it in your C# scripts like so:
GameController gc = new GameController();
You can then access any methods or properties just as you would with any other class.
in my scene have a button while button clicked nextScene = 1 activated
if(nextScene == 1) {
///////acces js pgm from here
}
shows error as like follows, my .js name is ScriptName.js
error CS0246: The type or namespace name `ScriptName' could not be found. Are you missing a using directive or an assembly reference?
Answer by Parthon · Apr 04, 2011 at 08:41 PM
Are you just wanting to access the script directly, or call a function on a component. They are two different things, so careful how you word it.
I'm not sure if you can GetComponent from C# to javascript because of how type-strong C# is.
Have you tried a SendMessage? use SendMessage("functionname",argument);
no i haven't tried send message............. ya i wanna access the whole script
in that case you would try
ScriptName script = GetComponent();
to get the script