MultiplayerTutorial.pdf
(
2206 KB
)
Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Unity Multiplayer Tutorial
For using Networking in Unity.
Author: Andrius Kuznecovas
Last Revision: 24-MAR-2010
Contents
1.
Multiplayer Tutorial
1. Introduction
3
2. Getting Started
3
3. Creating Your First Client / Server Application
4
3.1 Preparing Scene
4
3.2 Creating Scripts & Adding Components
5
3.2.1 Server & Client
5
3.2.2 Scene & Objects Instantiation On The Network
8
3.3 Quick Overview
10
4. Implementing Multiplayer in Startrooper
11
4.1 Changing Scene
11
4.2 Integration
11
4.2.1 Integrating Objects & Scene
11
4.2.2 Server & Client
21
4.3.3 Final Polishing
37
4.3 Quick Overview
38
Multiplayer Tutorial
Welcome, Unity User.
Here you will learn
advanced usage of Unity
Networking.
Have a great time and we
hope that this tutorial will
be helpful.
1. Introduction
The aim of this tutorial is to show the essence of Unity Networking. We will show
how to create basic and advanced network applications using Master Server/Client,
UDP Server/Client and Direct Connect. In this tutorial we will use Unity iPhone 1.6,
iPhone 3GS and the StarTrooper demo from the Unity web site.
2. Getting Started
There are a few things that you should know before you start.
•
You will learn how to:
Use basic and advanced components of networking.
Create a server and client.
Use the Master Server.
Use Direct Connect.
Use UDP Broadcast Server.
Create a simple scene on the network.
Convert the StarTrooper game to multiplayer.
Use other Unity components and more.
•
You should have:
Unity iPhone 1.6.
iPhone or iPod.
Knowledge about networks and how they work.
Advanced C# and JavaScript skills.
Basic Unity skills. You can find more information
here
.
•
Important notes:
Unity supports .NET 1.1 and 2.1.
You can disable or enable Networking in: Edit -> Project Settings -> Player
-> Enable Unity Networking.
Unity Networking supports wifi, 3G and GSM connections.
You can connect between diferent types of Unity targets. For example you
can connect from Unity on the desktop to Unity iPhone, from Unity Web
Player to Unity iPhone, etc.
3. Creating Your First Client / Server Application
In this chapter, we will cover the basics needed to create a simple multiplayer ap-
plication. We will create our first example featuring moving objects on the network
and basic handshaking between the client and server. The example uses all basic
multiplayer components such as:
Network
and
NetworkView
. We will use Direct
Connect for connection between client and server.
3.1 Preparing Scene
•
Now let’s start with a simple scene. Your first steps:
Create a new Project.
Create a new Prefab and name it Player: Assets -> Create -> Prefab.
Create a new Cube GameObject: GameObject -> Create other -> Cube.
Drag your Cube from the Hierarchy to your Player Prefab in the Project and
then delete your Cube from the scene.
4
Create a new Plane and name it Ground: GameObject -> Create other ->
Plane. Your Plane parameters should be: Position (0,0,0), Rotation (0,0,0),
Scale (5,5,5).
Create a Directional Light: GameObject -> Create other -> Directional Light.
Light parameters: Position (0,15,0), Rotation (25,0,0), Scale (1,1,1) Shadows
-> Type -> Soft Shadows.
Finally, save your scene and name it MainGame: File -> Save Scene.
Everything should look like this image:
3.2 Creating Scripts & Adding Components
•
Next you will learn how to create the server and client, instantiate the scene and
objects on the network, move objects, and connect everything together.
3.2.1 Server & Client
•
We will start with the most important — the creation of Server and Client:
Create a new JavaScript file and name it ConnectionGUI: Assets -> Create ->
JavaScript.
Add this file (by dragging) to the Main Camera object in the Hierarchy, then
open the file and create some variables:
var remoteIP = "127.0.0.1";
var remotePort = 25000;
var listenPort = 25000;
var useNAT = false;
var yourIP = "";
var yourPort = "";
5
Plik z chomika:
Verathez
Inne pliki z tego folderu:
Character Customization.unitypackage
(42676 KB)
Tree Creator Tutorial Assets.unitypackage
(41139 KB)
C Game Examples.unitypackage
(12655 KB)
CarTutorial.zip
(217060 KB)
3DPlatformTutorialStart.zip
(162979 KB)
Inne foldery tego chomika:
Assets
Zgłoś jeśli
naruszono regulamin