Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by ben · Mar 10, 2011 at 06:18 PM · c#javascriptgetcomponentfunction

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer Wiki

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ben · Apr 13, 2011 at 12:59 PM 0
Share

@alberthci - thank u very much

avatar image
-1
Wiki

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ben · Mar 10, 2011 at 07:11 PM 0
Share

its not working

avatar image ben · Mar 10, 2011 at 07:13 PM 0
Share

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

if(nextScene == 1) {

     ///////acces js pgm from here    
             
         }
avatar image ben · Mar 10, 2011 at 07:15 PM 0
Share

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?

avatar image
0
Wiki

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ben · Apr 05, 2011 at 12:34 PM 0
Share

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

avatar image Parthon · Apr 06, 2011 at 07:27 AM 0
Share

in that case you would try

ScriptName script = GetComponent();

to get the script

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How to call a c-sharp function from javascript? 1 Answer

Error when using GetComponent<> in a C# script, on a javascript 2 Answers

Component is null? 1 Answer

Calling Functions Within A Script? 1 Answer

Calling JS Static Function from C# Script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges