x


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

more ▼

asked Mar 10 '11 at 06:18 PM

ben gravatar image

ben
39 18 21 25

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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...

more ▼

answered Apr 12 '11 at 02:17 PM

alberthci gravatar image

alberthci
17 2

@alberthci - thank u very much

Apr 13 '11 at 12:59 PM ben
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 10 '11 at 06:40 PM

Steven Walker gravatar image

Steven Walker
862 25 32 49

its not working

Mar 10 '11 at 07:11 PM ben

in my scene have a button while button clicked nextScene = 1 activated

if(nextScene == 1) {

    ///////acces js pgm from here  

       }
Mar 10 '11 at 07:13 PM ben

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?

Mar 10 '11 at 07:15 PM ben
(comments are locked)
10|3000 characters needed characters left

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);

more ▼

answered Apr 04 '11 at 08:41 PM

Parthon gravatar image

Parthon
225 3 4 11

no i haven't tried send message............. ya i wanna access the whole script

Apr 05 '11 at 12:34 PM ben

in that case you would try

ScriptName script = GetComponent();

to get the script

Apr 06 '11 at 07:27 AM Parthon
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4359
x3565
x497
x421

asked: Mar 10 '11 at 06:18 PM

Seen: 4149 times

Last Updated: Mar 10 '11 at 06:18 PM