"ref float" is not compatible with the argument list "float"

I’m really drawing a blank as to why this is happening.

`var angle: float = Vector3.Angle(v1,v2);

transform.rotation.ToAngleAxis(angle,Vector3.up );
`

I get this error

The best overload for the method ‘UnityEngine.Quaternion.ToAngleAxis(ref float, ref UnityEngine.Vector3)’ is not compatible with the argument list ‘(float, UnityEngine.Vector3)’.

Someone told me “ref passes a reference rather than a copy, so var changes in the function propagate to caller scope” but I am not grasping the problem and how to fix this.

Any help would be appreciated!

1 Answer

1

I believe the issue may be that you’re passing Vector3.up as the vector. That is a system value and cannot be changed. Try this…

Vector3 up = Vector3.up;
transform.rotation.ToAngleAxis(angle, up);

If you’re using C#, you also have to specify that the parameters are output parameters when you call the function…

transform.rotation.ToAngleAxis(out angle, out up);

yes, although, in this case, it is 'ref' instead of 'out' :)

@Loius According to the [documentation][1] it's out :) [1]: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.ToAngleAxis.html