Local Multiplayer (New Input System)

Handling players joining through scripts

You don’t have access to this lesson
Please register or sign in to access the course content.
Length: 10 minutes

The PlayerSpawnManager Script

Now we are ready to create the PlayerSpawnManagerScript.

Create a new C# Script called PlayerSpawnManager and attach it to the PlayerManager object.

Open PlayerSpawnManager in your editor.

Line 4 includes the InputSystem

The Start and Update methods have been removed.

The OnPlayerJoined() method is added.

Add a Debug.Log(“Player Joined”); statement to the method to test the code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerSpawnManager : MonoBehaviour
{
    void OnPlayerJoined() {
        Debug.Log("PlayerInput Joined");
    }
}

Press the play button and join a player as usual.

We can see that when a player joins the Log is printed to the console.