Need help converting javascript to c#

Hi guys,

I’m not a programmer so I got no clue how to really do it hehe.

Could anyone help me convert this?

#pragma strict

var row:int = 0;
var column:int = 0;

var xOffset:float; 
var yOffset:float;
var offset:Vector2;

private var realX:float;
private var realY:float;

var mesh:MeshFilter;

var uvs:Vector2[];

var originalUVs:Vector2[];

function Start () {
//Get mesh to edit
mesh = GetComponent(MeshFilter);
originalUVs = new Vector2[mesh.mesh.uv.length];
originalUVs = mesh.mesh.uv;

//initialize new array
uvs = new Vector2[mesh.mesh.uv.length];
offset = Vector2(xOffset,yOffset);

for(var i:int = 0; i<mesh.mesh.uv.length; i++){
if(mesh.mesh.uv_.x>0&&mesh.mesh.uv*.y<1*_

&&mesh.mesh.uv_.x < 1 &&mesh.mesh.uv*.y>0){
mesh.mesh.uv.x = 1-mesh.mesh.uv.x;
mesh.mesh.uv.y = 1-mesh.mesh.uv.y;
}
}*_

for(var j:int = 0;j<mesh.mesh.uv.length; j++){
uvs[j] = originalUVs[j] + offset;
}

mesh.mesh.uv = uvs;
}

function Update () {
offset = Vector2(xOffset,yOffset);

for(var i:int = 0; i<mesh.mesh.uv.length; i++){
uvs = originalUVs + offset;
}

mesh.mesh.uv = uvs;
}
Thanks in advance :slight_smile:

There are several pitfalls in converting this code to C#: the default scope for variables is public in JS and private in C#, GetComponent has a different syntax, the array property length must be capitalized and Vector2 requires a new keyword. Besides this, a C# script must be explicitly declared as a class derived from MonoBehaviour - remember to replace YourScriptName in the class declaration below by the actual name you’re saving this script (the file name must match the class name):

using UnityEngine;
using System.Collections;

public class YourScriptName : MonoBehaviour {

	// variables are public by default in JS, but are private in C#:
	public int row = 0; 
	public int column = 0;
	 
	public float xOffset; 
	public float yOffset;
	public Vector2 offset;
	 
	float realX;
	float realY;
	 
	MeshFilter mesh;
	 
	Vector2[] uvs;
	 
	Vector2[] originalUVs;
	 
	void Start () {
		//Get mesh to edit - GetComponent is different in C#:
		mesh = GetComponent<MeshFilter>();
		// the array property "length" may start with lower case
		// in JS, but must be capitalized in C#
		originalUVs = new Vector2[mesh.mesh.uv.Length];
		originalUVs = mesh.mesh.uv;
		//initialize new array
		uvs = new Vector2[mesh.mesh.uv.Length];
		// Vector2/3/4 require a keyword "new" in C#:
		offset = new Vector2(xOffset,yOffset);
		 
		for (int i = 0; i<mesh.mesh.uv.Length; i++){
			if(mesh.mesh.uv_.x>0 && mesh.mesh.uv*.y<1*_

&& mesh.mesh.uv_.x < 1 && mesh.mesh.uv*.y>0){
mesh.mesh.uv.x = 1-mesh.mesh.uv.x;
mesh.mesh.uv.y = 1-mesh.mesh.uv.y;
}
}*_

* for (int j = 0; j<mesh.mesh.uv.Length; j++){*
* uvs[j] = originalUVs[j] + offset;*
* }*

* mesh.mesh.uv = uvs;*
* }*

* void Update () {*
* offset = new Vector2(xOffset,yOffset);*

* for(int i = 0; i<mesh.mesh.uv.Length; i++){*
uvs = originalUVs + offset;
* }*

* mesh.mesh.uv = uvs;*
* }*
}