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 piedoom · Aug 31, 2013 at 01:51 AM · c# to javascript

Converting simple C# to Javascript

 using UnityEngine;
 using System.Collections;
 
 public class GUI : MonoBehaviour {
     
     Rect rect = new Rect(0,0,Screen.width,Screen.height/2);
     public static bool rightArrow = false;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         
         if (Input.touchCount > 0)
         {
         for (int i=0; i < Input.touchCount; i++)
             {
             Touch touch = Input.GetTouch(i);
             Vector2 vec = touch.position;
             if(rect.Contains(vec))
                 {
                 ;
                 }
             }
         }
     
     }
 }

I need to convert the above to Javascript, as the rest of my game is in that language and I need to call the variable "rightArrow".

Are there any C# to unityscript converters out there? I've seen plenty the other way around... it's a little frustrating that they don't seem to work both ways (You'd think they would...)

If anyone knew both languages (and I feel badly even asking this) I couldn't thank you more if you were able to rewrite this. I've been stuck on this GUI issue, and someone was kind enough to give me this solution (unfortunately it's not in the language I'm comfortable with)...

Either that, or if anyone has some good links for translating. (It's much appreciated if you don't redirect me to the "Learning how to script" page on Unity - I've seen it searching through searching through a million other questions here ;).

Comment
Add comment · 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 AlucardJay · Aug 31, 2013 at 02:22 AM 0
Share

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/

Check the Unity Scripting Reference, at the above-right of every script example, there is a drop-down box. Click Javascript, then select C# to see the same example in each language.

avatar image robertbu · Aug 31, 2013 at 02:25 AM 0
Share

Here is a good description of the differences between the two languages:

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

This is pretty easy code to convert. I encourage you to take a shot. If you get stuck, post back your effort, and I'm sure someone will help you fix any remaining details. Having a basic understanding of both languages is very helpful when interacting with UA. Note na$$anonymous$$g your class GUI is not a good idea given Unity's GUI class.

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Im trying to make a C# program that outputs text on the screen like a typewriter. How would I do this? 1 Answer

Access a public class from C# script in JavaScript 0 Answers

How to use Farseer Physics (C# Package) in Javascript? 1 Answer

Passing constructor parameters in UnityScript 1 Answer

Convert c# to javascript 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