Help with convertion Js to C#

i need help, can someone make this for me? convert this script to c# please…

//LookAt
var damping = 6.0;
var smooth = true;

// The target we are following
var target : Transform;
var CamTarget : Transform;
var counter = 0;

// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we 
var heightDamping = 2.0;
var rotationDamping = 3.0;


var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = -20;
var yMaxLimit = 80;

private var x = 0.0;
private var y = 0.0;


// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Mouse Orbit RPG")

function Start () {
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;
	
	
	
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function LateUpdate () {
	Counter();
	// Early out if we don't have a target
	if (!target)
		return;
	
	//Ativa orbital botão direito do mouse
	 if(Input.GetMouseButton(1)){
	   counter = 0;
	   if (target) {
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;
        transform.position = position;
    }
   }else{
   //	CamTarget.position = Vector3(target.transform.position.x, target.transform.position.y + height, target.transform.position.z - 10);
  
  	//lookAt
  	if (target) {
		if (smooth)
		{
			// Look at and dampen the rotation
			var Lrotation = Quaternion.LookRotation(target.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, Lrotation, Time.deltaTime * damping);
		}
		else
		{
			// Just lookat
		    transform.LookAt(target);
		}
	}
  
   	
	if(counter == 4){
	// Calculate the current rotation angles
	var wantedRotationAngle = target.eulerAngles.y;
	var wantedHeight = target.position.y + height;
		
	var currentRotationAngle = transform.eulerAngles.y;
	var currentHeight = transform.position.y;
	
	// Damp the rotation around the y-axis
	currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

	// Damp the height
	currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

	// Convert the angle into a rotation
	var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
	
	// Set the position of the camera on the x-z plane to:
	// distance meters behind the target
	transform.position = target.position;
	transform.position -= currentRotation * Vector3.forward * distance;

	// Set the height of the camera
	transform.position.y = currentHeight;
	
	// Always look at the target
	transform.LookAt (target);
		}
	}
	
}

function Counter(){
	if(counter == 0){
		yield WaitForSeconds(1);
		counter = 1;
	}
	if(counter == 1){
		yield WaitForSeconds(1);
		counter = 2;
	}
	if(counter == 2){
		yield WaitForSeconds(1);
		counter = 3;
	}
	if(counter == 3){
		yield WaitForSeconds(1);
		counter = 4;
	}

}

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

thanks!

this is an easy conversion… if you want to use C# by converting this yourself you’ll learn so much… I could do it in 5 mins but i wont because u wont learn nothing… give it a shot if you have trouble reply to this and i’d be glad to help… good luck

ok, regardless of the post, I was trying to solve, but still have some errors

Unity will tell you where the faults are… had a quick scan…

Vector4 position = rotation * Vector3(0, 0, -distance) + target.position;

pretty sure there aint no vector4 :stuck_out_tongue:

you can use this website. Convert unity javascript (unityscript) to C#

Vector4 :smile:

Boom.

using UnityEngine;
using System.Collections;

public class MouseOrbitRPGcs : MonoBehaviour {

//LookAt
//var damping = 6.0;
//var smooth = true;
public float damping = 6.0f;
public bool smooth = true;

// The target we are following
//var target : Transform;
//var CamTarget : Transform;
//var counter = 0;
public Transform target;
public Transform CamTarget;
public int counter = 0;

// The distance in the x-z plane to the target
//var distance = 10.0;
public float distance = 10.0f;

// the height we want the camera to be above the target
//var height = 5.0;
public float height = 5.0f;

// How much we 
//var heightDamping = 2.0;
//var rotationDamping = 3.0;
public float heightDamping = 2.0f;
public float rotationDamping = 3.0f;

//var xSpeed = 250.0;
//var ySpeed = 120.0;
public float xSpeed = 250.0f;
public float ySpeed = 120.0f;

//var yMinLimit = -20;
//var yMaxLimit = 80;
public int yMinLimit = -20;
public int yMaxLimit = 80;

//private var x = 0.0;
//private var y = 0.0;
private float x = 0.0f;
private float y = 0.0f;

// Place the script in the Camera-Control group in the component menu
[AddComponentMenu("Camera-Control/Mouse Orbit RPG C#")]

// Use this for initialization
void Start () { 
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;

// Make the rigid body not change rotation
if (rigidbody){
rigidbody.freezeRotation = true;
}

}

// Update is called once per frame
void LateUpdate () {
	Counter();
	// Early out if we don't have a target
	if (!target)
	return;
	
	//Ativa orbital botão direito do mouse
	if(Input.GetMouseButton(1)){
		counter = 0;
	if (target) {
		x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
		y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

		y = ClampAngle(y, yMinLimit, yMaxLimit);

	Quaternion rotation = Quaternion.Euler(y, x, 0);
	Vector3 position = rotation * new Vector3(0, 0, -distance) + target.position;

	transform.rotation = rotation;
	transform.position = position;
}
	}else{
		//lookAt
		if (target) {
		if (smooth)
	{
	// Look at and dampen the rotation
		var Lrotation = Quaternion.LookRotation(target.position - transform.position);
		transform.rotation = Quaternion.Slerp(transform.rotation, Lrotation, Time.deltaTime * damping);
	}
	else
	{
		// Just lookat
		transform.LookAt(target);
	}
}


if(counter == 4){
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;

var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;

// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;

// Set the height of the camera
CamTarget.transform.position.y = currentHeight;
				
// Always look at the target
transform.LookAt (target);
//}

}
}
}
IEnumerator Counter(){
		if(counter == 0){
			yield return new WaitForSeconds(1);
			counter = 1;
		}
		if(counter == 1){
			yield return new WaitForSeconds(1);
			counter = 2;
		}
		if(counter == 2){
			yield return new WaitForSeconds(1);
			counter = 3;
		}
		if(counter == 3){
			yield return new WaitForSeconds(1);
			counter = 4;
		}
}
void ClampAngle (float angle, float min, float max) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}

}

i’m with 4 errors
1º - at line 79
2º - at line 127
and 2 errors at line 159

It would be helpful if you told us what the errors are.

ok…
line 79 = Cannot implicitly convert type void' to float’
79 —> y = ClampAngle(y, yMinLimit, yMaxLimit);

line 127 = Cannot modify a value type return value of UnityEngine.Transform.position'. Consider storing the value in a temporary variable 127 ---> CamTarget.transform.position.y = currentHeight;`

line 159 = MouseOrbitRPGcs.ClampAngle(float, float, float)': A return keyword must not be followed by any expression when method returns void. line 159 = Cannot implicitly convert type float’ to void' 159 --->return Mathf.Clamp (angle, min, max);`

//EDIT
problem at line 127 solved

currentHeight = currentHeight;

lol theres a vector4!

THE FOURTH DIMENSION

I knew I should of googled

Take that out since it does absolutely nothing.

thanks everybody problems solved :smile: