Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Solved] Help convert CSharp to Java.

Discussion in 'Scripting' started by GhulamJewel, Aug 22, 2016.

  1. GhulamJewel

    GhulamJewel

    Joined:
    May 23, 2014
    Posts:
    351
    Usually convert Java to Sharp with help of this. But don't know the other way. Can someone convert this? Thank you.

    Code (CSharp):
    1.  
    2.  
    3. void OnGUI() {
    4.  
    5. float scalex = (float)(Screen.width) / 700.0f;
    6. float scaley = (float)(Screen.height) / 500.0f;
    7. GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scalex, scaley, 1));
    Should it be something like this?

    Code (JavaScript):
    1.  
    2.  
    3. function OnGUI () {
    4.  
    5. var scalex;  float = Screen.width / 700.0f;
    6. var scaley;   float = Screen.height / 500.0f;
    7. GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scalex, scaley, 1));
     
  2. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    The C# block you posted is actually valid Java. JavaScript/UnityScript is not Java. I think this is what you're looking for:

    Code (JavaScript):
    1. function OnGUI () {
    2. var scalex : float = Screen.width / 700.0f;
    3. var scaley : float = Screen.height / 500.0f;
    4. GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scalex, scaley, 1));
    Try throwing that into your converter and see if it spits the C# code out.
     
    GhulamJewel likes this.
  3. GhulamJewel

    GhulamJewel

    Joined:
    May 23, 2014
    Posts:
    351
    Yeah the second block was correct. Although didn't know Java and Javascript two different things! :p Thanks.