- Home /
unexpected convert float to int error
i'm trying to increment the x coordinate of a vector2 by a certain amount (defined in the inspector), but it says that it cannot implicitly convert from type float to int. i don't understand why i'm getting this problem because the value i'm incrementing it by is a float. the code i'm using to increment it is below.
position.y += spacing;
this is the code i'm using to define the variables
public float spacing;
public Vector2 position;
please help, i have no idea what's going wrong.
Are you sure the problem comes from the given line?
Are you sure you don't have a local variable in yoru function called spacing
?
Answer by jandd661 · Sep 15, 2018 at 11:55 AM
Greetings, what you have here should work as far as data types. My only suggestion at the moment is to be careful of using "keywords" as variable names. It can cause some weird things happen. So position
might be better as targetPosition
or something. If it's not that, then something else is going on in the code. Hope this helps.
Your answer
Follow this Question
Related Questions
Error in Camera Tutorial that I can't seem to get right. 1 Answer
Why is my float not fitting into my AddForce script? 1 Answer
Multiplying Vector2 from another script. 2 Answers
The given key was not present in the dictionary, i am calling the key immediately after adding it 1 Answer
Errors in Vector2 variables 1 Answer