• 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
Question by ina · Dec 28, 2010 at 02:48 PM · variablegetcomponentexposejs-c#-together

Is there a way to reference a variable in another script if it's a different type of script?

Suppose you have most of your game created in js, but you are trying to reference a variable in a cs script. Using Find(otherObj).GetComponent(ScriptName) will automatically assume you are using the .js - how do you specify that you are using the .cs?

Comment

People who like this

0 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 Peter G · Dec 28, 2010 at 03:41 PM 0
Share

Actually your first notion is incorrect. Unity does nothing to assume you are referring to a js script. Often, not always, js scripts are compiled before C# scripts that are in the same compilation phase.

avatar image ina · Dec 28, 2010 at 05:13 PM 0
Share

yes it turned out to be the compile issue - js searched before cs unless it's in the plugin directory etc

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Loius · Dec 28, 2010 at 03:59 PM

If you're having a problem with compile-time errors - Try creating a folder called "plugins" or "Plugins" (not sure if capitalization is important) and putting your .cs files in there. THat'll cause them to be compiled earlier than most other scripts, and your .js files will know about their variables.

It's not that Unity assumes you're using JS, it's that Unity hasn't compiled the CS files yet so it doesn't know about them.

Comment
Greg 4
dai1741

People who like this

2 Show 0 · 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

Answer by Berenger · Dec 28, 2010 at 02:59 PM

I've never tried it, but I t$$anonymous$$nk Unity translate all your scripts in somet$$anonymous$$ng standard, so every class are registred the same way, either they are from .cs or .js, and the Find() won't care about it. That's what I t$$anonymous$$nk anyway.

Comment

People who like this

0 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 ina · Dec 28, 2010 at 03:00 PM 0
Share

so there's no way to tell between a js and cs?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Having to use the inspector during run time 1 Answer

How to get Component from Game Object in C# 1 Answer

Problems assigning transforms on another script during Start(). 2 Answers

How can i make GetComponent(SCRIPT) apply to ONLY ONE object that has the script? 1 Answer

Find + GetComponent not working as expected 0 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