There are two types of inputs in the UVC kits:
- General Input (input scripts using the General Input base class)
- Vehicle Input (input scripts using the Vehicle Input Base class)
General input is for handling input that is not specific to a vehicle, such as game menu navigation. It comes with some useful functionality, such as the ability to add conditions in the inspector that must be met for the script to run.
General input scripts can be placed anywhere in the scene.
To create your own general input script, extend the General Input base class with your own script.
Vehicle input is input that is run for a specific vehicle, for example a spaceship controller script. Vehicle input scripts extend the General Input base class, and must be placed in the hierarchy of a Game Agent.
A Game Agent gathers and stores all the Vehicle Input scripts in its hierarchy when the scene starts, and attempts to run them when it enters a new vehicle.
To create your own vehicle input script, create a new script that extends the Vehicle Input base class.
When a Game Agent enters a new vehicle, it calls the 'Initialize' function of each of its Vehicle Input scripts, passing the vehicle reference as a parameter to the function.
If the 'Initialize' function succeeds, it returns True, otherwise it returns False.
This is important, because in the 'Initialize' function, you can:
- Determine if the vehicle is the correct type for the script, and store a reference to the vehicle.
- Check if the vehicle has the components that the input script needs, and store references to them.
- Prevent the script from running by returning False in the Initialize function if it does not find what it needs.
To add your input code to your vehicle input script, override the 'Input Update' function and add your code. This function is called in Unity's Update loop when the script is successfully initialized and enabled.
To enable or disable input temporarily during gameplay, call the Vehicle Input script's 'Enable Input' or 'Disable Input' functions:
// Enable your vehicle input script
// Disable your vehicle input script
Sometimes you have an input script that needs to do something when it cannot carry out its function. You can add code to the 'On Input Update Failed' function, which is called every time the 'Input Update' function is called without succeeding.