Help Converting JS to C# please

Found some scripts I want to use but they’re all in js and my entire project is C#.
Only one I am not sure of is this one for the crosshair.
If anyone could help please it would be great.

@script ExecuteInEditMode()
var crosshair : Texture2D;

function OnGUI () {
    var w = crosshair.width/2;
    var h = crosshair.height/2;
    position = Rect((Screen.width - w)/2,(Screen.height - h )/2, w, h);

    if (!Input.GetButton ("Fire2")) {
        GUI.DrawTexture(position, crosshair);
    }
}

Only one part that I am not really sure what to do with is the 2 vars in the OnGUI function.

function OnGUI () {
    var w = crosshair.width/2;
    var h = crosshair.height/2;

Not sure what to call them in C#.

var should work

w and h are floats.

float w = crsoshair.width / 2;
etc

Automatic converter if you need (It doesn’t do variable types, but like I said those 2 are floats)
http://www.m2h.nl/files/js_to_c.php

you mean ints

1 Like

Oops, my bad, I do :stuck_out_tongue:

1 Like

Thanks a bunch for the help both of you.
@aaro4130
I knew about that converter already and use it when I get stumped but like you said it won’t fix everything.