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 LeftyTwoGuns · Jun 19, 2014 at 01:16 AM · c#javascriptconvert

Trouble with converting some JS code to C#

I have a nice object pooling script written in JS but I need C#. I've been teaching myself C# and don't know jack about JS, so I'm going through it slowly. I've come to a few lines where I don't quite understand their function or how to convey it in C#:

 static var instance : EasyObjectPool;
 
 function Start () {
     
     instance = this;

Particularly, I don't understand the first line. It's not really like anything I've seen in C# before. EasyObjectPool is the name of the script this code is in. I'd post the full script but this "instance" variable is only used in these lines, so I don't figure the rest is necessary. The JS code is calling "instance" a variable (right..?) but I don't know what to call it in C#.

Any input is appreciated

Comment
Add comment · Show 1
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 UnityDevelopper · Jun 19, 2014 at 01:30 AM 2
Share

so is easyobjectpool the class or a variable if a variable

 static public EasyObjectPool instance;
  
 void Start () {
  
     instance = this;
 }

If you need help in the rest of the conversion I try to help

1 Reply

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

Answer by tapir · Jun 19, 2014 at 01:29 AM

It seems like you are using a singleton pattern. You can use the same name for the variable. Normally you use singleton variables to avoid having multiple instance of a class. For example EasyObjectPoolController could instance an instance of EasyObjectPool, only if the static varibale EasyObjectPool.instance is null.

For more about singleton pattern this is the wikipedia article, its a basic start. Hope it helps!

 public class EasyObjectPool
 {
     static EasyObjectPool instance;
 
     void Start ()
     {
         instance = this;
     }
 }


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 LeftyTwoGuns · Jun 19, 2014 at 01:52 AM 0
Share

Thanks, that's a new concept to me. Whether the rest of my script will be right or not I don't know yet but I'll ask a separate answer is the final thing is giving me problems

avatar image tapir · Jun 19, 2014 at 02:01 AM 0
Share

I'm glad it helped. I just translated all my project (50+ scripts) from js to c#, so I might be able to help with that. I wrote a custom python script that translated my very strict js. You definitely want that if you are dealing with lots of scripts.

There is also an online translator for that, but I'm a bit paranoid and don't like the idea of uploading my code to someone's computer, so I didn't used it so I have no idea if it works or not.

Link to online translator: http://www.m2h.nl/files/js_to_c.php

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make this line work in C#? 1 Answer

Help converting this to C# - a few issues 3 Answers

java to C# conversion 1 Answer

What is this C# code in javascript 0 Answers

Converting a javascript 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