Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Assign input device in script

Discussion in 'Input System' started by M4RS_music, Jan 15, 2022.

  1. M4RS_music

    M4RS_music

    Joined:
    Nov 30, 2020
    Posts:
    2
    Using the input system I have a script for a third person controller. In that script i have some statements declaring what methods to run when an input action is performed it looks like this:

    Code (CSharp):
    1. PlayerControls controls; //This is the input action asset
    2.  
    3. void Awake()
    4.     {
    5.         controls = new PlayerControls();
    6.  
    7.         controls.Gameplay.Block.performed += ctx => BlockBegin();
    8.         controls.Gameplay.Block.canceled += ctx => BlockEnd();
    9.         controls.Gameplay.Dodge.performed += ctx => DodgeBegin();
    10.         controls.Gameplay.Dodge.canceled += ctx => DodgeEnd();
    11.         controls.Gameplay.Roll.performed += ctx => Roll();
    12.         controls.Gameplay.StimPulse.performed += ctx => StimPulse();
    What I need to do is tell it to only listen to one input device. Ideally something like this:

    Code (CSharp):
    1. controls.InputDevice = Gamepad.all[0]
    2.  
    3. ///Then in an identical copy of this script i would change it to
    4.  
    5. controls.InputDevice = Gamepad.all[1]
    6.  
    7. ///This way i could have local multiplayer
    I need to do this because I cant spawn in a new prefab with player input manager, there are too many things that need to be done manually to my player objects.

    PLEASE PLEASE, if you have any idea or suggestions on how I could do local multiplayer without spawning new prefabs you would literally be the reason I manage to complete this final project. I cannot find anything on this, its to the point where if I do manage to do it I will be making a guide on youtube as to how to do it, I dont believe it should be this hard to figure out.
     
  2. BionicowStudio

    BionicowStudio

    Joined:
    Jun 25, 2021
    Posts:
    2
    I´m about to give up with the new input system, I have the same problem and I can´t find any possible solution to the problem. Did you solve it??