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 /
avatar image
0
Question by Pyroglyph · Sep 06, 2014 at 05:06 PM · c#js-c#-together

Reference a JS script in a C# script?

Hi, I have a (modified) ThirdPersonController.js script that I want to reference in another script, Cheats.cs, which is coded in C#. When I try to reference the JS script (which is inside my Player) it doesn't appear like the CharacterController does, I've looked round the forums and nothing helped. It acts like the ThirdPersonController doesn't exist.

I have 2 theories to why this might be happening:

  1. C# can not access JS scripts.

  2. You can not reference a script, only a component.

I'm more inclined to believe in the first one. I'm happy to explain this further if you don't understand some of it.

Comment
Add comment · Show 2
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 Malfegor · Sep 06, 2014 at 06:21 PM 0
Share

It's true that C# cannot directly access JS, had this issue too. I've got a project, though, in which I had a JS file and put it in the Strea$$anonymous$$gAssets folder inside my Unity project, after which the JS script did still not show up as a 'suggestion' for finishing a word in $$anonymous$$onoDevelop, but could be used as a reference. Hope this helps!

avatar image AlucardJay · Sep 07, 2014 at 04:51 PM 0
Share

This has been answered many many many times before...

http://answers.unity3d.com/questions/385582/how-to-connect-2-scripts-using-c-js.html

2 Replies

· Add your reply
  • Sort: 
avatar image
-2
Best Answer

Answer by aman_jha · Sep 06, 2014 at 06:36 PM

Sadly, your first theory is correct. I've tried almost every possible way to connect them, but to no avail. Your best bet would be to convert the JS to C#. If it's not incredibly complex I can help. I've gotten fairly good at converting JS to C#.

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 Eric5h5 · Sep 06, 2014 at 06:38 PM 0
Share

Read the link tanoshimi posted. It's very possible to access JS from C#, but it's one-way (the JS script will not be able to access the C# script).

avatar image Pyroglyph · Sep 07, 2014 at 03:03 PM 0
Share

Converted to C# (my preferred language) and everything works fine! I have to agree it is easy to convert from JS to C# when you know what you're doing (as with everything). I'm actually considering converting all the base scripts into C# in case I need them later on.

avatar image
0

Answer by Ssiroo · Sep 06, 2014 at 06:40 PM

This worked for me :

Create a folder named Plugins in the main Assets folder and put your script in there, then unity should recognise it and will allow you to access it from other scripts.

I hope it works for you too.

Good luck.

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Does My GameObject Not Spawn Anymore? 2 Answers

How may I get the children (direct and dependents) of a game object? 2 Answers

Problem with Pause and Pause Menu Script 1 Answer

Distribute terrain in zones 3 Answers

How to call Variable across scripts. 2 Answers


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