- Home /
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 ;).
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://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.
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.
Your answer
