Another way of doing input action for buttons

Another way of doing the input action for button pressing, is the “triggered” bool value. Reading the current documentation for Input Systems (Actions | Input System | 1.0.2).

I wrote my method like this.

private void ProcessFiring()
    {
        if (fire.triggered)
            Debug.Log("I'm Shooting");
    }

Didn’t realize this was going to bite me later in the next lessons. This seems to be a usecase for a flashlight toggle maybe, or an interaction with a door. However in this use case having the recognition of an input being pressed and held is required. Actions | Input System | 1.3.0 Somehow I was looking at old documentation on this system in my previous work. Using “IsPressed()” method on InputAction that returns a bool. If holding the button it will continue to return true until release.

Here is my code now…

private void ProcessFiring()
    {
        if (fire.IsPressed())
        {
            SetLasersActive(true);
        }
        else
        {
            SetLasersActive(false);
        }
    }

    private void SetLasersActive(bool isActive)
    {
        foreach (var laser in lasers)
        {
            var emission = laser.GetComponent<ParticleSystem>().emission;
            emission.enabled = isActive;
        }
    }

Cheers!

1 Like

Privacy & Terms