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
5
Question by Kronusdark · Sep 03, 2012 at 11:57 PM · c#importnewbielibraries

External Libraries in C# scripts

Just want to say first of all that I have a C/Objective-C programming background. I am new to Unity and C#.

That said, is there a way to #include or #import in unity? I cannot seem to figure out how to import classes from other files without assigning them to a game object (which seems a little complicated considering how easy unity makes other things). So, is there an import method, and how do I use it? If not how should I be using external code sources?

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

1 Reply

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

Answer by kmeboe · Sep 06, 2012 at 05:10 PM

Hey,

There is no "#include" directive in c#. Any .cs files in your asset folder are accessible to all other scripts; you don't need to attach them to a game object first. Note that unless a method in a class is declared "static" (like "alloc" in objective c), you will need to have an instance of that class before you can use it. For example:

 public class TestClass 
 {
 
   static void ThisMethodIsStatic()
   {
     // do stuff
   }
 
   void ThisMethodIsNonStatic()
   {
     // do other stuff
   }
 
 }
 
 
 // inside a different script.....
 void Update()
 {
   TestClass.ThisMethodIsStatic(); //okay
 
   TestClass.ThisMethodIsNonStatic();  // Won't compile, instead use the below
 
   TestClass instanceOfTestClass = new TestClass();
   instanceOfTestClass.ThisMethodIsNonStatic();
 }

In addition, I believe that any .net assemblies in your "Assets" folder will also be available for use, but I haven't tried this myself.

Does this help?

-Kevin

Comment
Add comment · Show 9 · 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 Kronusdark · Sep 06, 2012 at 05:13 PM 0
Share

Absolutely! thank you very much. Can you help me with one more thing? What is the deal with first and second passes?

avatar image kmeboe · Sep 06, 2012 at 05:18 PM 0
Share

Okay, I have a confession...I'm a little new to Unity myself. :)

Are those passes a compilation thing? I haven't noticed them.

avatar image Kronusdark · Sep 06, 2012 at 05:21 PM 0
Share

I think it has something to do with javascript vs c#, but I am not sure how it works. if you look in the project explorer in monodevelop, it shows 2 different sections for the passes.

avatar image kmeboe · Sep 06, 2012 at 05:24 PM 0
Share

Oh right...the "...firstpass.csproj" files. I'm not sure why Unity has those, but they are essentially "temporary" files that are used for the build. You can delete them, and the framework will recreate them. If you're using an SC$$anonymous$$ system (like Perforce), you don't need to add these files to the repository.

avatar image ThermalFusion · Sep 06, 2012 at 05:25 PM 3
Share

http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html That should probably answer that.

Show more comments

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

11 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

OpenFilePanel, but how? - SOLVED! -1 Answers

Question on UnityScript and C# 1 Answer

How to import an element when the game is build 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