How do I reference either the x or y field of a Vector2 depending on some condition?
Hello. I'm resizing a grid, to do so I use two functions, the first resizes the grid in the X axis, the second on the Y axis. I would like to merge them but I have difficulties coming up with a solution.
My main issue is that I would need to have some way to tell the method to either use (and update, very important) the x or y field of a Vector2 depending on some boolean (if changeXAxis = true then use coordinates.x else use coordinates.y, if it makes sense).
I have tried multiple things, for example setting variables with a ternary operator like so:
But then
coordinateX
become it's own variable, I have tried using the ref
keyword in different ways but couldn't get it to make this work.
Is there some concept I'm not aware of that would solve my issue or am I stuck with two methods that do basically the same thing?
On a side note, I know I should put the ModifyGrid()
outside of the UpdateTiles()
one but this is very much a work in progress still.
I'm putting my current method below because it's just slightly too big to comfortably fit in an image. The other is the same, just inverted basically.
1 Reply
I think the issue you are running into is that Vector2 is a type of struct which is a value type and you are trying to use it like a reference type.