The last stage of the character is its code class. The code class will receive input from the PlayerInput class we wrote earlier, so the character can be controlled through the input and filter out the type of GameObjects that collided with from the parent of that collider type.
Perform the following steps:
To start with, navigate to the Assets/Scripts
folder and right-click on it. Select Create and then C# Script. Name it Character
.
Next, we need to give our PlayerInput
class a reference to our character. To perform this, navigate to the Assets/Scripts
folder and double-click on the PlayerInput.cs
file to open it.
At the top of the class, under the SimpleTouch
struct, add the following code:
public Character GameCharacter;
We also need to tie the function that will call GameCharacter
when PlayerInput
gets a new one. At the bottom of the CalculateTouchInput
function, add the following code:
if (GameCharacter != null...