Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 BlackWingsCorp · Apr 22, 2013 at 03:23 PM · javascriptconvert

Writing with c# and javascript simultaneoulsy

Hey guys what's up? I code with javascript but understand well c#. I'm following the unity stealth tutorial and since it's written in c# translating it into js is pretty hard. So I was wondering if I can use both languages simultaneously. Since unity works in both languages can it convert the scripts from one to another so they can both work together?

Comment
Add comment · Show 9
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 Jessy · Apr 22, 2013 at 03:46 PM 3
Share

If you understand C# well, why would you use JavaScript?

avatar image BlackWingsCorp · Apr 22, 2013 at 03:55 PM 1
Share

Lol I dunno I guess I liked it's simplicity.

avatar image Fattie · Apr 22, 2013 at 04:40 PM 1
Share

Unityscript is terrific and very natural for Unity3D. This has been said over and over: the fact is you need to be pretty good at both. I don't think there's any way around that, ultimately be fairly good at both of those, for Unity. the fact is Unity is "bilingual."

avatar image Jessy · Apr 22, 2013 at 04:58 PM 0
Share

Its lack of features make working with it difficult, not simple. Your response tells me that you don't actually know C# well, and I recommend you go check out what it uniquely offers in Unity.

avatar image AlucardJay · Apr 22, 2013 at 04:59 PM 1
Share

Good point Fattie =]

Here is my generic C#_JS post : Here's some links I found useful in converting between C# and JS :

  • http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

  • http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

  • http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

Edit : though absolutely as whydoidoit states, you should only use one language per project.

Show more comments

3 Replies

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

Answer by ahaykal · Apr 22, 2013 at 03:49 PM

Well you can use them together, everything will work normally but you have to know which script you want to compile first. A lthough from my personal experience I prefer to use only one language (Preferably c#).

Unity doesn't convert the scripts from one to another, however you can use this to convert from C# to unity-script.

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 BlackWingsCorp · Apr 22, 2013 at 03:56 PM 1
Share

I just tested it. Can't believe a converter actually works. Thanks alot mate

avatar image
2

Answer by Julien-Lynge · Apr 22, 2013 at 03:43 PM

Yes, you can absolutely use both simultaneously. The caveat is that if you're going to communicate cross-language, you need the class you're going to call to be compiled first. For example, if you have MyCS.cs and you want to call a method in MyJS.js, MyJS.js has to be compiled in an earlier step than MyCS.

You can get a list of the compilation steps here:

http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html

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 BlackWingsCorp · Apr 22, 2013 at 04:00 PM 0
Share

10x bro. apparently they were right. C# is more powerful then js

avatar image
2

Answer by Bunny83 · Apr 22, 2013 at 03:56 PM

It's very easy to convert UnityScript to C#. Take a look at my answer on this question

Comment
Add comment · Show 5 · 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 Bunny83 · Apr 22, 2013 at 03:58 PM 0
Share

Watch out: Coroutines can't be decompiled to C# due to some tricks the compiler does when it's compiling them.

avatar image BlackWingsCorp · Apr 22, 2013 at 04:10 PM 0
Share

seems legit 10x alot.

avatar image Fattie · Apr 22, 2013 at 04:37 PM 2
Share

Just FWIW. A useful common trick is:

You'll have some c# class sitting in Plugins. Because it's in Plugins, basically your Unityscript can call it no problem.

But, you want to "get back to" your unityscript world. You want to call something in the Unityscript world.

It's almost always easiest to just do this ..

 public class BlahBlah : $$anonymous$$onoBehaviour 
 {
     public static event Action<string> informationIsReadyEvent;
     .. blah blah..
 
     void someFunction()
         {
         if( informationIsReadyEvent != null )
              informationIsReadyEvent( stuff, stuff );
         blah blah
         }

then over in your unityscript land, inside some .js file ...

 function Awake()
     {
     BlahBlah.informationIsReadyEvent+= aNormalFunction;
     }

then you merely do this

 function aNormalFunction( height:Float, fatness:float )
     {
     blah blah ...
     }

the function aNormalFunction() will run completely normally whenever you call informationIsReadyEvent up in the c# codebase.

I hope it helps you or some other readers!

avatar image BlackWingsCorp · Apr 22, 2013 at 04:53 PM 0
Share

Thanks bro. that's gonna help alot when it comes to jumping from c# to js & vice versa

avatar image Fattie · Apr 22, 2013 at 04:55 PM 0
Share

right. often "all" of your scripts are unityscript, and important stuff is c# - in the plugin folder! this is how you get "back" to the unityscript, often.

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

17 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

Related Questions

Multiple Cars not working 1 Answer

How can i make the ray cast don't go through the walls 1 Answer

Add force to GameObject 2 Answers

BCE0044: expecting }, found 'private'. PLEASE HELP!!!!! 2 Answers

Why isn't my word generator working? 1 Answer


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