0
votes

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!

1
What error are you getting? Please provide more information. - aribeiro
I strongly recommend trying to debug on your own (along with Google's help) before you post on SO. Also, @aribeiro mentioned, it helps to post the error that you receive and also what you've tried to correct it with yourself. All the best! - andeart
surprisingly, perhaps incredibly, I don't think this is a duplicate @andeart - it's the first! - Fattie
@JoeBlow That's funnily surprising. I do feel the need to sigh each time something like this shows up on SO. - andeart
What environment do you use for programming? The current compiler of visual studio is compiling it without issues. - Felix K.

1 Answers

1
votes

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);