5 - Building the Player
This section will guide you to create from scratch the player Prefab that will be used in this tutorial so that we cover every step of the creation process.
It's always a good approach to try and create a player Prefab that can work without PUN being connected so that it's easy to quickly test, debug and make sure everything at least works without any network features.
Then, you can build up and modify slowly and surely each feature into a network compliant character:
Typically, user input should only be activated on the instance owned by the player, not on other players' computers.
We'll cover this in details below.
The Prefab Basics
The first and important convention to know about PUN is that for a Prefab to be instantiated over the network, it needs to be inside a Resources folder, it can not be otherwise.
The second important side effect of having Prefabs inside Resources is that you need to watch for their names.
You should not have two Prefab under your Assets' Resources paths named the same, as Unity will pick the first one it finds, so always make sure that within your Project Assets, there is no two Prefabs within a Resources folder path that is named the same. We'll get to that soon.
We are going to use the Kyle Robot that Unity provides as a free asset.
It comes as an Fbx file, which is generated by 3D software like 3ds Max, Maya, cinema4d and the likes.
This is out of scope for this tutorial to cover the creation of the mesh and animation on these tools, however essential for creating your own characters and animations.
This "Robot Kyle.fbx" is located in "Assets\Photon Unity Networking\Demos\Shared Assets"
- In your "Project Browser", create a folder named exactly "Resources" somewhere, typically it's suggested that you organized your content, so could have something like "PunBasics_tutorial\Resources"
- Create a new empty scene and save it as
Kyle Testin "PunBasics_tutorial\Scenes".
The purpose of the "Kyle Test" scene is solely to create the prefab and set it up.
You can get rid of the scene once this is done. - Drag and drop
Robot Kyleonto the "Scene Hierarchy". - Rename the GameObject you've just created in the hierarchy to
My Robot Kyle - Drag and drop
My Robot Kyleinto "PunBasics_tutorial\Resources"
We have now created a Prefab that is based on Kyle Robot Fbx asset and we have an instance of it in the hierarchy of your scene Kyle Test.
Now we can start working on it.
CharacterController
- Let's add a CharacterController Component to
My Kyle Robotinstance in the hierarchy.
You could do this directly on the Prefab itself but we need to tweak it, so this is quicker this way.
This Component is a very convenient Standard Asset provided by Unity for us to produce faster typical characters using Animator, so let's make use of these great Unity features.
Back to top- The Prefab Basics
- CharacterController
- Animator Setup
- Assigning an Animator Controller
- Working with the Controller Parameters
- Animator Manager Script
- Animator Manager: Speed Control
- Test, test, 1 2 3...
- Animator Manager Script: Direction Control
- Animator Manager Script: Jumping
- Camera Setup
- PhotonView Component
- Beams Setup
- Health Setup