Hello!
My problem
I’m trying to make a simple couch coop game but every time, someone pushes a button on any controller, the input action from every player gets triggered.
The setup
I have a gameObject with a playerInputManager component attached:

The player prefab has a playerInput component:

I also added my own playerController script to it.
playerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class playerController : MonoBehaviour
{
Input controls;
public boxController boxController;
[SerializeField]
int playerNr;
void Awake()
{
controls = new Input();
controls.threeBoxes.boxLeft.performed += context => inputForwarder("boxLeft");
controls.threeBoxes.boxMiddle.performed += context => inputForwarder("boxMiddle");
controls.threeBoxes.boxRight.performed += context => inputForwarder("boxRight");
}
private void Start()
{
boxController = GameObject.Find("threeBoxes").GetComponent<boxController>();
playerNr = gameObject.GetComponent<PlayerInput>().splitScreenIndex;
}
]void inputForwarder(string whichInput)
{
boxController.inputReceiver(whichInput, playerNr);
}
private void OnEnable()
{
controls.threeBoxes.Enable();
}
private void OnDisable()
{
controls.threeBoxes.Disable();
}
}
boxController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class boxController : MonoBehaviour
{
public void inputReceiver(string whichInput, int playerNr)
{
Debug.Log(whichInput+" "+playerNr);
}
}
And if press any button on one of the controllers, I get the Debug.Log message two times (always first from the first player, then from the second one, regardless of who pushed the button).
I absolutely don’t get why that happens … do you have any idea, what the problem could be?
Thank you very much! ![]()
