Code reuse in practice – Adding premade components to the player
In addition to refactoring some existing code to work in our new project, we can also bring in our existing system code – this could then be considered premade components, ready for use. So, referring back to the GDD now, we will use HealthSystem
from the 2D adventure game project to decrease and recharge the player’s power suit (i.e., health).
If you don’t already have the 2D adventure game scripts locally, you can download the project source from the GitHub repo here: https://github.com/PacktPublishing/Unity-2022-by-Example
Now, from the 2D adventure game project, copy the following files into the 3D FPS game project (in the same locations):
- From
Assets/Scripts/Systems
HealthSystem.cs
- From
Assets/Scripts/Interfaces
IHeal.cs
IDamage.cs
IHaveHealth.cs
Now that the health system has been added to the project, the first thing to do is refactor any of the 2D API methods and...