-1
\$\begingroup\$

I get an error every time I try making a line with "new Vector3".

Example 1: private Vector3 playerPos = new Vector3 (0, .5, 0); gives the error:

The best overload method match for 'UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments

Example 2: playerPos = new Vector3 (Mathf.Clamp (xPos, -8, 8), .5, 0f); gives the same error.

I followed the exact line from this video except my y's are different (my doing) and this isn't the first time I had a new Vector3 problem either.

I'm also using 5.0.1 (DX11 if that helps also) and I have not found any solutions. I am quite new to this but Copy and Pasting isn't very hard. (If I do his y axis I get the same problem so it's not that.) I really need help and thanks in advance.

\$\endgroup\$
  • 1
    \$\begingroup\$ Try using 0.5f instead of just 0.5. I can't see why you should be having this problem with just playerPos = new Vector3(0, .5, 0); \$\endgroup\$ – Zee Jun 27 '15 at 1:26
3
\$\begingroup\$

If you don't specify an f at the end of a decimal value in C#, it's assumed to be of type double. To preserve precision, double does not implicitly cast to float.

So because of the .5 you put in the y (rather than the -9.5f in the tutorial's code), your examples have the signatures:

new Vector3(int, double, int)
new Vector3(int, double, float)

...both of which can convert implicitly to new Vector3(float, double, float), but that middle argument won't convert to the float type the constructor is expecting unless you explicitly cast it or append an f.

\$\endgroup\$
  • \$\begingroup\$ That worked, thank you very much. But now every time I try and run it (F5) it wants to "Attach to Process" and opens a new window. I have no idea why and every time I "Attach" it opens a new Unity program and I believe it's from an older version. (Also it seems my C&P wasn't 100 :P) \$\endgroup\$ – Magic Jun 27 '15 at 0:28
  • \$\begingroup\$ @Magic, it's worth asking another question about that. If you're running it from Monodevelop/Visual Studio/other code IDE, try running it from Unity instead by clicking the play button. I'll confess I don't run with a debugger attached very often, so I don't know the correct flow when running the project from a code IDE. \$\endgroup\$ – DMGregory Jun 27 '15 at 0:31
  • \$\begingroup\$ Ah, alright. It doesn't seem to really do anything since it saves my codes once it's "complete" but thank you anyway. \$\endgroup\$ – Magic Jun 27 '15 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.