The best overloaded method match for?

Hello all right?

He was accompanying a video lesson to make camera movement, and in the videothe example is displayed in javascript, I’m trying to convert to C #, but I’m having some small problems, the editor of Unity accuses the following errors:

Assets/Camera.cs(30,28): error CS1502: The best overloaded method match for `UnityEngine.Physics.Linecast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit, int)’ has some invalid arguments

Assets/Camera.cs(30,28): error CS1620: Argument #3' is missing out’ modifier

Assets/Camera.cs(33,48): error CS1502: The best overloaded method match for `UnityEngine.Mathf.SmoothDamp(float, float, ref float, float)’ has some invalid arguments

Assets/Camera.cs(33,48): error CS1620: Argument #3' is missing ref’ modifier

Could someone help me identify the error. Thank you.
Code below:

using UnityEngine;
using System.Collections;

public class Camera : MonoBehaviour {
	public float height;
	public float distance;
	public float damping;
	public float cameraCollisionTolerance;
	public Transform target;
	private float yVelocity;
	private float zVelocity;
	private Transform t;
	void Awake () {
		t = transform;

	void LaterUpdate () {
		// Calcula a posiçao desejada para a Camera ficar
		float localX = 0;
		float localY = height;
		float localZ = -1 * distance;
		Vector3 desiredWorldPosition = t.parent.TransformPoint(new Vector3(localX, localY, localZ));
		// Detecta se tem algum objeto obstruindo a visao da camera do jogador
		int layerMark = ~ (1 << 8);
		RaycastHit hit = new RaycastHit();
		if(Physics.Linecast(target.position, desiredWorldPosition, hit, layerMark)) {
			t.position = hit.point + (target.position - hit.point).normalized * cameraCollisionTolerance;
		} else {
			float yDamping = Mathf.SmoothDamp(t.localPosition.y, localY, yVelocity, damping);
			float zDamping = Mathf.SmoothDamp(t.localPosition.z, localZ, zVelocity, damping);
			t.localPosition = new Vector3(0, yDamping, zDamping);

The errors tell you exactly what your problem is.

“Assets/Camera.cs(30,28): error CS1620: Argument #3’ is missingout’ modifier”

On line 30, by the 28th character, the 3rd argument of the function is missing the out modifier.

So, you simply add the out modifier:

if(Physics.Linecast(target.position, desiredWorldPosition, out hit, layerMark))
//Add "out" right before "hit"

then, On line 33, the third argument is missing the “ref” modifier.

So, once again, you simply add the ref modifier:

float yDamping = Mathf.SmoothDamp(t.localPosition.y, localY, ref yVelocity, damping);
//Right before "yVelocity", add "ref"

That should solve your errors. Unity is usually very precise in telling you in the error message what needs to be fixed, so try to look at them closely :p.

Have fun! :slight_smile: