Skip to content

Unity's Input System

I am having some trouble with the new Unity input system. I have been working along with some friends and I don't know how I feel about it.

We were trying to make a gun shoot when the play pushes in a controllers right trigger but cant get the bullets to shoot when you push in the trigger only when you meet the time required for the hold interaction. I also am using a tap interaction and tried it with a press but it only let one of them work at a time. ( either hold or tap/press at the same time)

I feel like the old input system is so much easier to work with but feel in order to get local multiplayer or just a controller to work "easier" I would need to learn about the new input system.

How does everyone else feel about the input system? Is there a way to learn it easier since the documentation isn't the best or videos that have explained it well? Everything I saw covers the basics but never shows making a more serious game or going over other methods/ using interactions

2 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 67% up
Kind
Text
ID
l11hur

Author

23
posts
12
comments
5
media
View profile

7 comments

Hope someone with experience answer here. I am in the same situation as you, I find the new input system too convoluted, for my simple games I am still attached to the good old 'Input.GetAxis()'

3 points

Yeah I definitely feel like they will move forward with trying to make the new input system their main source of input at some point in the future but they would definitely need to simplify it. The old input system is easy to use and works perfectly. I’ve just heard that the new system is easier for local multiplayer and controller support which are the reasons why I’m trying to learn it

3 points

I've been studying unity for a while, but I'm not sure what your problem is since I have no idea what kind of code you're writing.

Can you share the piece you're having trouble making work?

1 points

The code that I have goes like this.

Inside the awake function:

controls.PlayerBehaviour.Attack.performed += ctx =>
{
    if (!isRapidFire)
    {
        StartRapidFire();
    }
    };

    controls.PlayerBehaviour.Attack.canceled += ctx => StopRapidFire();
}

Methods that get called: private void StartRapidFire() {

    if (shootingSpeed == 0)
    {
        StartCoroutine(RapidFire());
        Debug.Log("StartedRapidFire");
    }
}

private void StopRapidFire()
{
    if (isRapidFire)
    {
        isRapidFire = false;
    }

    shootingSpeed = 0;

    StopCoroutine(RapidFire());
    Debug.Log("Stopped Rapid Fire");
}

private IEnumerator RapidFire()
{
    isRapidFire = true;

    shootingSpeed = weaponInHand.GetComponent<WeaponBehaviour>().fireRateMax;


    var currentWeapon = weaponInHand.GetComponent<WeaponBehaviour>();

    
    do
    {
        if (shootingSpeed > 0) shootingSpeed -= Time.deltaTime;


        Attack();
        yield return new WaitForSeconds(currentWeapon.fireRateMax);
    } while (isRapidFire);
}

private void Attack()
{
    if (weaponInHand != null)
    {
        weaponInHand.GetComponent<WeaponBehaviour>().Attack();
    }

    else
    {
        Debug.Log("Punching");
    }
}

Attack Script on the weapon that gets called:

public void Attack()
{
    if(_weaponAmmoCurrent > 0)
    {
        //shoot raycast
        Debug.Log("Shooting");

        _weaponAmmoCurrent--;
    }

    else
    {
        Debug.Log("Needs to reload");
    }
}

Sorry if there's any formatting problems I'm fairly new at reddit and don't use it much so I'm not sure how to format things properly

2 points

Hey, it looks great, I don't think I could format it that well.

Sorry for the delay in answering.

I'll start by saying what you're doing there is very different from how I've seen/done things, so I'm not sure I can help, but I'll try.

Not sure if this is something that happened because of the editing of the post but here:

if (!isRapidFire)
{
    StartRapidFire();
}
}; -- this bracket seems off to me

Also, you're not using the Update function?

I'm guessing this is what reads player input ?controls.PlayerBehaviour.Attack.performed

Also, why are you using a while with the waitforseconds there? Doesn't that lock you in the firing action? Though since it's a coroutine it might not, but did you try outside of a while to see if it doesn't fire with the press only?

Sorry for being so oblivious, I'm on the process of learning Unity and C# and figured, why not try to help.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.