UHFPS
  • 👋Welcome
  • 🎲Installation
    • URP - Project Setup
    • HDRP - Project Setup
    • Packages Setup
  • 🎮Getting Started
    • References
  • ⬆️Update Process
  • 📑Changelog
  • 📍Roadmap
  • ❔Support
  • 📚Guides
    • Managing Inputs
      • Adding Inputs to UI
      • Setting up Input System
    • State Machines
      • Adding Player States
      • Adding AI States
    • Save/Load Manager
      • Previous Scene Persistency
      • Encryption
    • Customizing UI
    • Interactions
    • Inventory
    • Player Items
    • Dynamic Objects
    • Motion Controller
      • External Motions
    • Hiding System
    • Narration System
    • Jumpscares
    • Puzzles
    • Objectives
    • Cutscenes
    • Options Manager
    • Game Manager
    • Localization
    • URP Specific
  • ⚙️Integrations
    • Emerald AI 3.0
    • AI Tree
    • Meet and Talk
Powered by GitBook
On this page
  1. Guides

Managing Inputs

PreviousSupportNextAdding Inputs to UI

Last updated 1 month ago

The asset utilizes the Unity Input System package, which means modifying inputs may differ from the old built-in Unity Input System. If you're unfamiliar with setting up the Input System package, please refer to the guide provided below.

  1. Locate the PlayerControls asset within the UHFPS -> Scriptables -> Input folder. To open the Input Actions window, double-click on the asset.

After opening the Input Actions window, you may notice that the action names follow the input.action.something pattern. This was in fact used as localization keys in previous versions of UHFPS. In the latest version of the asset this has been replaced with a better solution, so now it's up to you to name the inputs to your liking.

  1. To create a new input action, simply click on the (+) icon found to the right of the Actions tab name. Enter the name of the action in the localization key pattern.

Input names containing an asterisk (*) will be automatically excluded from menu display and serialization. For instance, input.action.look* will be disregarded.

  1. Select the newly created action and modify the Action Type to the desired input type.

  1. Next, click on the <No Binding> and choose the key you want your action to utilize.

  1. If you are using a custom controls asset, ensure that you assign the reference to this asset within the Input Manager component.

  1. In order to access input actions within a script, simply use the Input Manager functions. There are multiple ways to utilize the input.

using UnityEngine;
using UHFPS.Input;

private void Update()
{
    if (InputManager.ReadButtonToggle(this, Controls.CROUCH))
    {
        // do something when toggled on
        // even if you don't hold any button
    }

    if (InputManager.ReadButtonOnce(this, Controls.FIRE))
    {
        // do something once as button
    }

    if (InputManager.ReadButton(Controls.FIRE))
    {
        // do something every update as button
    }

    if(InputManager.ReadInput(Controls.LEAN, out float direction))
    {
        // do something every update with value
    }
}
using UnityEngine;
using UnityEngine.InputSystem;
using UHFPS.Input;

void Start()
{
    InputManager.Performed(Controls.FIRE, OnFire);
}

private void OnFire(InputAction.CallbackContext obj)
{
    // do something 
}
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UHFPS.Input;

IDisposable disposable;

void Start()
{
    disposable = InputManager.PerformedObservable(Controls.FIRE)
        .Subscribe(OnFire);
}

private void OnDestroy()
{
    // you have to dispose input event manually
    disposable.Dispose();
}

private void OnFire(InputAction.CallbackContext obj)
{
    // do something
}

You can find a script called Controls, which stores all the input names so that you don't have to keep typing out the whole input name over and over again.

📚
Setting up Input System