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 flaye · Nov 28, 2012 at 09:25 PM · c#javascriptconversion

Converting variable from javascript to C#

Hi,

I just started learning Unity and teaching myself C#. I'm following an online tutorial that uses JS, and I'm trying to convert the code to C#.

I've used the m2h.nl jsToC# converter site, and this is the error I'm getting:

Javascript:

private var instanBoosters;

C#:

private FIXME_VAR_TYPE instanBoosters;

I've tried assigning the var as a string or float, but I get the errors.

Any idea what can replace the variable type on that line? Thanks.

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
0
Best Answer

Answer by kag359six · Nov 29, 2012 at 02:33 AM

OK, so it depends on what you are instantiating the object as. Usually you would define it as transform. So it would be:

 Transform instanBoosters;
 
 //when you instantiate do this:
 
 instanBoosters= Instantiate(object,position,rotation) as Transform;
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 flaye · Dec 02, 2012 at 06:24 PM 0
Share

Thanks for the reply. I'll look more into this. I think it boils down to a level of familiarity with each language and the Unity particulars. It still doesn't properly work, but at least it's a direction I can explore more in depth.

avatar image
1

Answer by kag359six · Nov 28, 2012 at 11:05 PM

You have to know what the Type of object instanBoosters is, which is the issue with the dynamic nature of javascript. In javascript you don't have to define the type unless there is no value in it. In C# you can't just randomly switch the type. For example, you can't make an integer a float unless you cast. If it's a string you would do:

 String someString; //define type, then name of variable.

Do you know what type of object instanBoosters is?

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 Bunny83 · Nov 28, 2012 at 11:09 PM 0
Share

Exactly, just take a look at the script and find out where the variable is used. That's the only way to figure out what type it should have.

avatar image kag359six · Nov 28, 2012 at 11:45 PM 0
Share

Another recommendation is to take seperate lessons in C# as a language rather than for Unity itself. It helps understand it better.

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

12 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

Related Questions

Help with conversion from javascript to c# 3 Answers

Multiple Cars not working 1 Answer

Trying to convert this javascript code to C# 1 Answer

C# to Java Script Conversion 2 Answers

Distribute terrain in zones 3 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