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[1] that is an array[2] 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[3] 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[4] (Keyboard and Controller)

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

Terms definitions
2. array. A data[9] structure that is a collection of elements, each element has what is called an array index or key, which can be thought of as a pointer. And you can refer to that element by calling it’s index or key.
3. static. In relation to computing static usually means that something is unable to change. In relation to Object Orientated Programming[6] (OOP) static is used to refer to a variable or method that is used for multiple different objects. They can be called directly and do not need[10] an object to be instantiated (created) using a class.
4. inputs. If you do something, and a computer or system ‘receives’ that, you’ve given it input. If that input triggers a function[7], you might receive some kind of feedback[8] from the system.
5. system. A set of interconnected parts designed to transform, store, transport or control[11] materials, energy and/or information.
Terms definitions
1. variable. 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 […]
2. array. 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 […]
3. static. 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 […]
4. inputs. 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 […]
5. system. 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 […]