Creating a New Project with Existing Project Assets for 2.5D Platformer in Unity 2021
In this article we’ll start fresh with a new project, albeit with assets and a scene provided from GameDevHQ in my case.
We’ll also pull in assets from our project in previous articles.
GameDevHQ Provided Files
If you have access to GameDevHQ’s filebase, search their tutorials section for “2.5d” and download / import the “2.5D Starter File”.
I’ve also downloaded and imported the 2.5D Platformer project which is not listed in the Tutorials section, though I’m not sure if I’ll be using it just yet.
For ease of access, I’ve copied the provided scene to the standard “Scenes” folder.
Now is a good time to make a commit to your GitHub account.
I’ll be using the new Input System again, so we’ll need to install this from Package Manager.
We’ll also need to install the Cinemachine package.
I’m not sure if we’ll cover UI in this project, but I will be pulling over files from the previous project which reference the UI and thus TMPro Essentials.
With that being the case, I might as well import TextMeshPro Essentials now.
I prefer not to reinvent the wheel, so I’ll bring over some scripts and prefabs that will be necessary to implement my current Player prefab as shown above.
Simply open your project from previous articles in Windows Explorer, go to the Assets folder and copy/paste what you need.
We’ll also want to copy over our InputActions asset file (not the .cs file) from the previous project.
Select the InputActions asset file in the Project window and then click “Generate C# Class” and “Apply” in the Inspector window.
We should see a newly generated C# script next to our InputActions asset file in the Project window.
Since I did not bring over the Coins class/script, our console is throwing some exceptions due to references to the missing script.
Since coins is only referenced in the OnTriggerEnter() method of the PlayerInventory class/script, this is an easy fix.
Simply comment out the coins related code that is currently not in use.
If we do implement coins in the future, we can always import the Coins script from the previous project and reenable this code.
Prefabs Missing Scripts
I had thought that copying over the scripts before the prefabs would avoid this issue, but Unity lost all references to the scripts on each of the prefabs brought over from the previous project.
With the previous project open in a separate Unity Editor on a 2nd monitor, I simply went through and re-added all necessary scripts to the prefabs.
Above I had an issue with the VCam_PlayerFollow prefab that you should not.
I hadn’t installed Cinemachine at this point, but you should have prior to importing this prefab if following along with this article.
We will need to modify some settings (Follow / Look At) on our VCam_PlayerFollow prefab, but we have to get the player prefab in the scene first.
Player Prefab Default Values
Let’s set our Player prefab’s default values as shown above.
Next, drag in the prefabs in the order shown and then assign their settings as shown above.
Using GameObject > Align With View, we can easily position our player game object just above the platform.
When we hit start, he’ll fall to the correct height on the platform.
We then can set the height on the Player game object as just slightly higher.
Go ahead and copy these values over to Level Manager for the player’s starting position field.
This way, if the player falls off they can reset to this location.
Because our previous project had some game objects tagged and we have no custom tags in this project, the console is throwing errors.
These are that tags in our previous project.
Add them to this project.
The GameDevHQ provided level has a different orientation from our previous project.
Holding the “A” button moves backwards, rather than left!
Rotate the Level
Select the Level parent game object, and hold control while you rotate it until it is properly aligned in the scene.
For me, this was a Y rotation of 90.
We’ll need to reset our player position and copy those values to the LevelManager.
VCam Not Working
Clearly our virtual camera is not working.
For our virtual camera(s) to work, the MainCamera must have the CinemachineBrain component added to them.
That’s it for this article.
Next time we’ll implement a character model with animations!