Player Controls (New Input System)

Different colour players

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

Create materials for each player colour.

Open the PlayerController script

Add in a public variable that is an array of Material objects.

Set the array to be the maximum number of players.

Save the script

On the player prefab there is now the option to manually assign values to the items in the array. This isn’t efficient but it works.

Assign the player colour materials to the array.

Go back to the Player Controller script.

Add a static local variable index and set this to 0, the first position in the array of playerColours. The use of static means that this variable is shared across all versions of the player objects.

In the Start() method add in GetComponent<Renderer>().material = playerColours(index);

This gets the materials of the renderer usedon this object and assigns the material stored in the array.

Run the game and use two different inputs (Keyboard and Controller)

A limitation of the iput system is that Keyboard is only able to be used as one input,