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.
[ 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()”.