help me please translate the code from Java to C #

#pragma strict

var target : Transform;
var smoothTime = 0.5;
private var thisTransform : Transform;
private var velocity : Vector2;

function Start()
{
	thisTransform = transform;
}

function Update() 
{
	thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, 
		target.position.x, velocity.x, smoothTime);
		
	thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, 
		target.position.y, velocity.y, smoothTime);
}

At first I’d say, that code translation doesn’t really belong at answers.unity. But, then again… I’ve been there, and it was hell till I got proper grip.

using UnityEngine;
using System.Collections;

public class CSharpScriptName : MonoBehaviour
{
	public Transform target;
	public float smoothTime = 0.5f; //this might be a dobbelt
	private Transform thisTransform;
	private Vector2 velocity;
	
	void Start()
	{
		thisTransform = transform;
	}
	
	void Update()
	{
		thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, 
       	target.position.x, velocity.x, smoothTime);

    	thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, 
       	target.position.y, velocity.y, smoothTime);
	}
}

C# is class based and extends Monobehavior to work with unity. Variable declarations are somewhat different. The functions are written a bit differently, but I am quite sure that most interaction with unity, through .position and such are just the same.

Enjoy

Thanks for the help!
But the compiler shows 6 errors (
alt text

There’s usually just two rules:

[ function X( arg : Type ) : Type ] becomes [ Type X( Type arg ) ]. If the function doesn’t have a : Type then it becomes void X.

[ var x : Type ] becomes [ Type x ].

By the way, the error messages you’re getting are pretty self-descriptive. You need to add the ‘ref’ keyword to the third argument of the function on line 18 and 21.

Mathf.SmoothDamp( x, y, ref z );

If you keep #pragma strict at the top of your JS, you won’t have to worry too often about type conversions. Otherwise you’ll need to address each compile error - they’ll say something like ‘cannot convert X to Z’; so you add “Z variable = *(Z)*TheFunction()”.

Thanks for the help!
Here is the correct translation:
using UnityEngine;
using System.Collections;

public class Camera_control : MonoBehaviour
{
     public Transform target;
     public float smoothTime = 0.5f; //this might be a dobbelt
     private Transform thisTransform;
     private Vector2 velocity;

     void Start()
     {
        thisTransform = transform;
     }

     void Update()
     {
         
         thisTransform.position = new Vector3(
             Mathf.SmoothDamp( thisTransform.position.x, target.position.x, ref velocity.x, smoothTime),
             Mathf.SmoothDamp( thisTransform.position.y, target.position.y, ref velocity.y, smoothTime),
             thisTransform.position.z);
     }
}