Marc Davidson
Marc Davidson

Reputation: 11

Error with Vector3 and float

In my game an object is printed out every few seconds.

But I get an error with my float values. Here is my code:

grassBarn.transform.position = new Vector3(43, 12, 0);

Errors like this appear

Assets/scripts/gameplay/Classname.cs(44,62): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments

and sometimes like this

Assets/scripts/gameplay/Classname.cs(44,62): error CS1503: Argument #2 cannot convert double expression to type float

Thanks!

Upvotes: 0

Views: 1549

Answers (1)

Jordan
Jordan

Reputation: 424

The Vector3 class works with float values.

When programming with C#, you have to use a f value and assign to your decimals to tell the compiler that you want them to be a float value. I suggest using this:

grassBarn.transform.position = new Vector3(43f, 12f, 0f);

Upvotes: 1

Related Questions