Skip to content

Instantly share code, notes, and snippets.

@christopherperry
Last active June 10, 2020 23:53
Show Gist options
  • Save christopherperry/c3605499912ee0c30602100bffd84216 to your computer and use it in GitHub Desktop.
Save christopherperry/c3605499912ee0c30602100bffd84216 to your computer and use it in GitHub Desktop.
Using more than one prefab with Unity's PlayerInputManager
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInputManagerHelper : MonoBehaviour
{
public GameObject redBoxerPrefab;
public GameObject blueBoxerPrefab;
public GameEvent onRedPlayerJoin;
public GameEvent onBluePlayerJoin;
private void OnPlayerJoined(PlayerInput playerInput)
{
if (PlayerInputManager.instance.playerPrefab == redBoxerPrefab)
{
onRedPlayerJoin.Raise();
}
else if (PlayerInputManager.instance.playerPrefab == blueBoxerPrefab)
{
onBluePlayerJoin.Raise();
}
PlayerInputManager.instance.playerPrefab = blueBoxerPrefab;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment