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
1
Question by Jaliborc · Jan 22, 2012 at 02:51 PM · c#c#-and-js

Make C# Class Globally Available on JavaScript

Lets say I have a class written in C#. Now I want to use it in many of my JS files. Is there a way to make it globally availabe, without the need to call

var theClass = GameObject.Find("SomeObject").GetComponent("C# Class")

each single time?

Comment
Add comment · Show 5
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 syclamoth · Jan 22, 2012 at 02:59 PM 0
Share

I'm not sure I understand your usage of the term 'globally available'. Wouldn't you have to use GetComponent to get a reference to an object, even if you could see the class? Are you trying to make JS classes talk to C# classes in a type-safe way?

avatar image Jaliborc · Jan 22, 2012 at 03:26 PM 0
Share

I mean that, independently of which Script I am coding in, that I could simply type:

  theClass.someStaticStuff

Ins$$anonymous$$d of

 var theClass = GameObject.Find("SomeObject").GetComponent("C# Class")
 theClass.someStaticStuff

In other words: to make the class name a global variable (such as the JS classes do).

avatar image Kryptos · Jan 22, 2012 at 09:52 PM 0
Share

I think you misunderstood the meaning of class. And I don't get what you mean by 'make the class name a global variable such as JS classes do'.

avatar image robbiek · Jan 22, 2012 at 10:02 PM 0
Share

Are you sure you dont mean make a function global?

avatar image Jaliborc · Jan 22, 2012 at 10:28 PM 0
Share

$$anonymous$$ryptos: No, I'm sure. Just think of it as placing the name from the namespace of script in one language (in this case, C#), into the namespace of others (in this case, JS files). I could simply set them as static values on every script (and connect them on "Awake"), but I am trying to understand if there is no better way to do it.

robbiek: No, I am interested in making a class, not a function, global. Because the namespace of scripts in different languages does not appears to be shared (the standard API is, but everything you define in one language is not available on the other).

0 Replies

· Add your reply
  • Sort: 

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

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

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Need help converting js to C 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