Could someone please show me HOW to convert this JavaScript snippet?

void Update () {
		if(Input.GetKeyDown(KeyCode.Mouse0))
		{
			var playerPlane = new Plane(Vector3.up, transform.position);
			var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			var hitdist = 0.0;
 
			if (playerPlane.Raycast (ray, hitdist)) {
				var targetPoint = ray.GetPoint(hitdist);
				targetPosition = ray.GetPoint(hitdist);
				var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
				transform.rotation = targetRotation;
			}
		}
		
		transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
	}

So I’ve converted some of this script already, but my knowledge of JavaScript is very minimal. I’d really like to know how to convert this snippet into C#, if someone is able to show me how I’d really appreciate it!

It’s already pretty much converted; just change 0.0 to 0.0f, and use “out hitdist” in the raycast.

–Eric

I’ve made those changes, but it’s telling me I don’t need the “out” modifier. Taking that out, my only error is a “Best overloaded match…” error, which I should be able to fix. Thanks for the help!

get rid of the out.

Wait, are you trying to convert it to or from C#? C# needs “out”, Unityscript does not.

–Eric

I don’t get any warning with the following code :

void Update () 
{
	if(Input.GetKeyDown(KeyCode.Mouse0))
		{
			Plane playerPlane = new Plane(Vector3.up, transform.position);
			Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			float hitdist = 0f;

			if (playerPlane.Raycast (ray, hitdist)) {

				Vector3 targetPoint = ray.GetPoint(hitdist);
				targetPosition = ray.GetPoint(hitdist);

				Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

				transform.rotation = targetRotation;
			}
		}
		transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
	}

Thats interesting, since when did the Plane.Raycast methods signature looks like this

bool Raycast(Ray ray, float enter);

http://docs.unity3d.com/Documentation/ScriptReference/Plane.Raycast.html

the enter argument should be with an out, was there a recent change or is the documentation flawed for the C# sample? I wonder because it doenst make sense without the out.

Looks like a documentation error; it’s correct in the 4.0 docs at least.

–Eric