NUIS part 3
Reading Values
We are not yet at the point we can use this code but we are in some pretty fascinating territory
When we add line 15 up to += and then hit the tab key two things happen:
- The rest of line 15 is generated
- the Method found at lines 18–21 is generated
This new method subscribes to the player input using the WASD keys and we can get some great information by modifying the new function. We will change ‘obj’ to ‘context’, create a Vector2 variable and read both in the console:
When the new code is run we can see that printing out the ‘context’ variable’s information is quite detailed. We can see the X & Z changes more easily in the move variable. I find that debugging using the move variable is often easier and faster to use.
Our Next Step: Develop the scene
Now all we need to do is create a ‘player’, a ‘vehicle’ & a plane and add a script to the ‘player’.
The script will use the information gained from the Input Action.
It will then send that information to the Player script so that it can enable the player’s movement.
Note: The following lines of code act similar to GetKeyDown, GetKey & GetKeyUp. Though wordy they are quite powerful.
With a core code like ‘Input Manager’ we can compartmentalize all of the input logic in one place to make future troubleshooting much easier.
Additionally, by allowing the Player to focus ONLY on it’s movement it becomes much less cluttered and easier to read/work on.
— — —