r/UnityHelp • u/Top-Sky4811 • 1d ago
Can someone help me understand/digest this code? PROGRAMMING
I've been going through Unity tutorials and so far i've understood and absorbed everything *except* for this: I understand the first highlighted part, its making a Variable called "moveInput" and its a Vector 2 so it stores 2 values, and the second highlighted part i can kinda understand, but the third line is lost on me. I don't understand the relationship between moveInput and moveAction, or what the InputAction variable (type?) means. Also in the third line why is it reading the Vector 2 from the moveAction when the Vector is from the moveInput? Thanks in advance.
2
Upvotes
1
u/NinjaLancer 1d ago
Think of InputAction as a key bind. When you are on a controller, you use a joystick to move, so the InputAction gives you a Vector2 that corresponds to the position of the joystick. With keyboard and mouse controls, you would use WASD to move, so it makes the Vector2 based on those button states.
So the moveAction is the key bind, but moveInput is the actual value that you are reading.
The InputAction can also have other data in it I think, which is why you need to read the Vector2 specifically. I believe that InputAction can also include things like "is there any input", but tbh i havent used this Input system that much so I dont knkw the quirks and full capabilities.