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 KhShani · Apr 12, 2014 at 12:07 PM · c#compile-error

How to access a static variable in c# from js

Hey ! Can anyone please help me in accessing a static int variable declared in c# from Javascript. I have keep in minded the compilation order but Still no luck . Your help would be appreciated Regards

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Gruffy · Apr 12, 2014 at 02:09 PM

Hey bud, If your code to access it is sound, you must then place the Java/UnityScript file into a folder named "Plugins" or anywhere below that folder (i.e. a folder structure like.. "Plugins->JS") This is due to what is known as script execution order. Both these language are not compiled together or even in the same way, making them incompatible until they are both at an intermediate stage etc. If you place your JS file in a Folder as mentioned above, you will ensure it is compile prior to any C# script accessing during compilation/setups etc. This link will be invaluable to you by the sounds of things to come, read it and bookmark it....

UnityGems

Take care bud. Gruffy

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 KhShani · Apr 15, 2014 at 10:58 AM 0
Share

Well thanks, Your comment helped me a lot and special thanks for the web link :)

avatar image nirharpaz · May 29, 2015 at 03:19 PM 0
Share

is it ok to ask for the link again? its broken atm, and i have the same problem

avatar image
0

Answer by ForeignGod · Apr 12, 2014 at 12:46 PM

State the scriptname before the variable like this. After writing this i realized that you actually cant access Javascript from C# But Javascript can atleast access C#.

 //1st script (script1)
 
 var MyVar = 1;
 
 function Start(){
 
      Myvar = script2.OnorOff;
 
 }
 
 //2nd script (script2)
 
 var OnorOff = 2;


 //Now MyVar is equal to you other OnorOff variable in another script.

 //Sadly, im not good in c# so this might not be what you need. 
 //But this is what i use to access other varibles in other scritps.
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 KhShani · Apr 12, 2014 at 01:59 PM 0
Share

I appreciate your thoughts but yes I this is not what i need :)

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

23 People are following this question.

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

Related Questions

Play specific animation in mechanim 1 Answer

Converting Autowaypoint (JS) to C# 1 Answer

Distribute terrain in zones 3 Answers

Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 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