Need help converting Javascript to C#

var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;
private var spawnPos : Vector3;
private var spawnRot : Quaternion;
public Transform patrolPoints;

function Start ()
{
	spawnPos = transform.position;
    spawnRot = transform.rotation;
}

function Update ()
{
	Distance = Vector3.Distance(Target.position, transform.position);
	
	if (Distance < lookAtDistance)
	{
		renderer.material.color = Color.yellow;
		lookAt();
	}
	
	if (Distance > lookAtDistance)
	{
		renderer.material.color = Color.green;
		patrol();
	}
	
	if (Distance < attackRange)
	{
		renderer.material.color = Color.red;
		attack ();
	}
}

function lookAt ()
{
	var rotation = Quaternion.LookRotation(Target.position - transform.position);
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}

function attack ()
{
	transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}

function patrol ()
{
	transform.position = spawnPos;
    transform.rotation = spawnRot;
}

Hi i was wondering how much of this code would i have to change to make it into C#. i need this code in C# for technical reasons with my game, but it would be greatly appreciated if anyone could point me in the right direction. i tried to go lone walk but had trouble making my variable work in C#, sorry im a complete noob at C# so any help would be greatly appreciated. thanks.

You only need 4 steps:

  • Download ILSpy
  • build your game with the javascript as standalone build.
  • Open the UnityScript assembly in the data folder of your build in ILSpy and select C# as target language.
  • Copy the code over into a c# script and delete the US script

That’s all

Try this free site. Just copy your JavaScript code and it will return in c#. http://www.m2h.nl/files/js_to_c.php

Change var to the type.

Remove the : type

Put a f after your floats

Change function to void