Giter Site home page Giter Site logo

multiplayerfps-tutorial's Introduction

Making a Multiplayer FPS in Unity

Learn how to make a multiplayer first-person shooter in Unity. This series teaches the very cool Unity Networking system (uNet). All code is written entirely in C#.

Watch the videos HERE.

###Software

  • This project runs on the Unity engine. Make sure to have the newest version installed before running the project. The project folder is called "MultiplayerFPS".

###Copyright This project is released into the public domain. For more information see LICENSE.

multiplayerfps-tutorial's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiplayerfps-tutorial's Issues

Player Layer Error

the Error says "A game object can only be in one layer. The layer needs to be in range [0....3]". The code is

void AssignRemoteLayer()
{
gameObject.layer = LayerMask.NameToLayer (remoteLayerName);
}

no cameras rendering

when I have watched the third video and did like the video said I tried to run the game in unity but it says "no cameras rendering"

ERROR

my unity says he couldn't play the game mode because assembly's are missing

1 issue

Hello,
When i press play in the main scene it unity gives me this issue. Please help!
I work with unity 5.6.2f1

1
2

Networking, Jumping, Aiming issue

Hi all. I'm still at the first few videos and I have encountered quite a few problems.

  1. Networking: I am using Mirror and there is a problem with the movement synchronisation. Every time the client enters, the two players will float away

  2. Jumping: Everytime I jump, the player just floats away and it floats and rotates at the same time

  3. Aiming: When I shoot the floor, it shows Cube prototype instead of floor.

Thank you. Really appreciate the help

RaycastHit _hit; if statement not working

Sometime between episode 12 and 13, my Raycast stopped detecting hits. Any idea what is happening?

Below is the Shoot(); I added debug.logs to find the error.

[Client]
void Shoot()
{
if (!isLocalPlayer)
{
return;
}

    //WE ARE SHOOTING, CALL THE ONSHOOT METHOD ON THE SERVER
    CmdOnShoot();

    RaycastHit _hit;
    if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, currentWeapon.range, mask))
    {
        Debug.Log("RaycastHit"); //DID NOT PLAY
        if (_hit.collider.tag == PLAYER_TAG)
        {
            CmdPlayerShot(_hit.collider.name, currentWeapon.damage);
        }

        //we hit something call the on hit method ont the server
        Debug.Log("raycasthit"); //DID NOT PLAY
        CmdOnHit(_hit.point, _hit.normal);
    }
    else
    {
        Debug.Log("nohit"); //DID PLAY
    }     
}

Not being able to log in / register.

When I click the Log In or Register button, I get an error and it buffers forever.
I'm using Unity 2018.2, and changed all of the DC's with DCF's and that's working fine.
The issue is that in the script LoginMenu.cs , at line 146, a variable called "returned" is being created, but on the next line, it's null, I have added a little part to the script to Debug.LogError if the WWW variable is null, and it does. Does anyone know how to solve this issue?

script
error

Network Manager For Hosting Players

networkManager.matchMaker.CreateMatch(roomName , roomSize , true , "" , "" , "" , 0 , 0 , networkManager.OnMatchCreate);

In Unity 2017 , it requires 9 arguments , either i didn't know the scenario ,
please correct me as i got a null reference error.

Episode 11 WeaponCamera Issues.

My WeaponCamera is not getting disabled. When I press play (with a player prefab already in the level) I see the prefabs weapon through walls, and it floats around the prefab it isn't attached. I get the same result from when I build the game. I have the WeaponCamera attached to the Player Setup scrips to disable. Any ideas?

The first image shows the camera is attached to the script (I am at 6 instead of 7 because I do not have the animation from moving the character, I plan on changing from a sphere to player model later).
camissue

The second image demonstrates what I see when I play (with player prefab or a building game).
playissue

the third image demonstrates the player weapon being shown through the wall.
throughwalls

All of this leads to me to believe the WeaponCamera is not being disabled properly, I was thinking it had something to do with its layer, but after rewatching the video he never changed the WeaponCameras layer.

NullReferenceException(muzzleflash)

The error is as follows:

NullReferenceException: Object reference not set to an instance of an object
PlayerShoot.RpcDoShootEffect () (at Assets/Scripts/PlayerShoot.cs:74)

Now the problem is that this error does not arise till the 2nd player joins the lobby. Once the second player joins the room, the 1st player(host of the room) starts getting this error.

So if I launch (host) the room from the Build and join the room from Unity itself, the Unity Player can do everything, but once he starts shooting, you cannot see his shooting in the Build game and the Build Player also cannot shoot and the NullReference error starts popping up. Then if the Unity Player kills the Build Player by shooting him, he only dies in the Unity Game and nothing happens in the Build Game.

SimpleActivatorMenu not working

When I try to fix the simple activator script, it says 'GUIText has been removed. Use UI.Text instead.' And then when I try it it says another thing.

Network Manager Issue Please help cant find any solution

This is what my error in the console :
Assets/Scripts/PauseMenu.cs(20,107): error CS1061: Type UnityEngine.Networking.NetworkManager' does not contain a definition for OnDropConnection' and no extension method OnDropConnection' of type UnityEngine.Networking.NetworkManager' could be found (are you missing a using directive or an assembly reference?)
and this same error is preventing my script to work.
Please Help me and provide me with any solution i searched a lot and dont know what to do.
Thanks in Advance and Sorry for my Bad English.

[Unity Editor]
capture1
[Visual Studio]
capture2

2 ISSUES:

#1-Loginmenu doesnt work, im not getting into the lobby | #2- No Models could be imported, blender files could not be loaded.

-->Please fix the errors!

Script is not working, help please

In Lectur no. 6 of Making a multiplayer FPS game-UNet, in PlayerShoot Script

using UnityEngine.Networking;
using UnityEngine;

public class PlayerShoot : NetworkBehaviour
{
private const string PLAYER_TAG = "Player";
public PlayerWeapon weapon;

[SerializeField]
private Camera cam;

[SerializeField]
private LayerMask mask;

void Start()
{
    if(cam == null)
    {
        Debug.LogError("PlayerShoot:No Camera referance");
        this.enabled = false;   
    }


}


void Update()
{
    if (Input.GetButtonDown("Fire1") )
    {
        Shoot();
    }
}

[Client]
void Shoot ()
{
    RaycastHit _hit;
    if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, weapon.range, mask) )
    {
        
       if (_hit.collider.tag == PLAYER_TAG)
       {
            CmdPlayerShot(_hit.collider.name);
       }

    }
}

[Command]
void CmdPlayerShot (string _ID)
{  
    Debug.Log(_ID + "Have Been Shot.");
            
}

}

It should show "We hit + Player ID" in console, but it is showing nothing.

Compile errors Unity 5.5.0b3

When I open the project in Unity Unity 5.5.0b3, I get compile errors - see attached screenshot.
I don't know how to fix it, please help.
errors

E.13 (Muzzle Flash)

Hi,

I'm getting an error:

NullReferenceException: Object reference not set to an instance of an object
PlayerShoot.Update () (at Assets/Scripts/PlayerShoot.cs:32)

This happens once a second player enters the network. The line that gives the error is:

    if (currentWeapon.fireRate <= 0f)
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Shoot();
        }

After Debugging - it seems that currenWeapon is assigned when the host is playing in the server - but as soon as a second client joins, this reference gets broken. Any ideas?

Here is my PlayerShoot Script: https://www.codepile.net/pile/BNWvbZRM
Here is my WeaponManager Script: https://www.codepile.net/pile/d3orgj1D
Here is my PlayerWeapon Script: https://www.codepile.net/pile/L8m56W8J

Player is going opposition

When i click to go to right, it goes to left. Also click to go left, it goes to right. I search the internet but I can't solve this.

Issues running it

Awesome project, exactly what I am looking for : When I run it I get

Invalid AABB result
aabb.IsFinite()
Invalid AABB a
Invalid AABB a
IsFinite(outDistanceForSort)
IsFinite(outDistanceAlongView)

respawn error/freeze/crash (Another NullReferenceException)

Respawn works find when hard coded, and VS seems to recognize that the field is a float value.

NullReferenceException: Object reference not set to an instance of an object
Player+c__Iterator0.MoveNext () (at Assets/Scripts/Player.cs:83)

Said Line:
yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTime);

looks like everything is spelled properly, I went into the code and compared all the lines to what I have by copying them into my project and using the Find feature to paste, no discrepancies found.

MatchSettings looks like:
[System.Serializable]
public class MatchSettings {

public float respawnTime = 3f;

}

GameManager (minus Player Tracking field):

using UnityEngine;
using System.Collections.Generic;

public class GameManager : MonoBehaviour {

public static GameManager instance;

public MatchSettings matchSettings;


void Awake ()
{
    if (instance != null)
    {
        Debug.LogError("More than one GameManager in scene.");
    } else
    {
        instance = this;
    }
}

issues

errors on unity4.6 and unity 5.0

Input Button Reload is not setup/auto firing

As I'm going through the demo and what not. I came across the issue of the weapon automatically firing after triggering it once and im not sure why this is. I am also getting my console spammed with the error that the input button Reload is not setup. (See full error below) Not entirely sure why this is happening, haven't messed with any of that code at all. any help would be appreciated. Thanks!
ArgumentException: Input Button Reload is not setup. To change the input settings use: Edit -> Project Settings -> Input PlayerShoot.Update () (at Assets/Maps/MultiplayerFPS-Tutorial-master/MultiplayerFPS/Assets/Scripts/PlayerShoot.cs:38)
I tried checking the input settings and i didnt see a reload input nor a way to add one, line 38 wasnt of much help either. thanks!

NetworkManager

I wonder is there a NetworkManager C# file?
PlayerMotor.cs, PlayerControler.cs, PlayerSetup.cs, NetworkManager.cs, or something that can show me how you did it so it work as it should. For now I have a lot of issues to fix the problems till I can play it. Some times it working, other time it will not work. Am using unity 5.3.5f1, after all trying I wonder the free unity are working as it should. I see you get player clone, I didn't, and so on. So you see I trying to understand it so I can go forward to making a game with unity.

I hope you can help me out, if you got the time.
Is there a possiable to make a new tutorial using newer unity like 5.3.5 ?
I wonder how to make a transporter, and other things like star trek :)
I understand a lot what you telling us but there will be a problem to make it when it not working like you showing in tutorials.

Keep up the good work!

pcontroler
pmotor
psetup
unity535f1_01
unity535f1_02
unity535f1_03

if statement of RaycastHit

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class PlayerShoot : NetworkBehaviour
{
private const string PLAYER_TAG = "Player";
private PlayerWeapon weapon;
[SerializeField]
private Camera cam;
[SerializeField]
private LayerMask mask;

void Start ()
{
	if (cam == null)
	{
		Debug.LogError("PlayerShoot: No camera referenced!");
		this.enabled = false;
	}
	
	//weaponManager = GetComponent<WeaponManager>();
}
void  Update()
{
	if(Input.GetButtonDown("Fire1"))
	{
		Shoot();
	}
}
[Client]
void Shoot()
{
	RaycastHit _hit;
	// below line gives me error
	if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, weapon.range, mask) )
	{
		//Debug.Log("we hit "+_hit.collider.name);
		if(_hit.collider.tag == PLAYER_TAG)
		{
			CmdPlayerShot(_hit.collider.name,weapon.damage);
		}
	}
}
[Command]
void CmdPlayerShot (string _playerID, int _damage)
{
	Debug.Log(_playerID + " has been shot.");

    Player _player = GameManager.GetPlayer(_playerID);
    _player.RpcTakeDamage(_damage);
}

}
// error : Object reference not set to an instance of an object

Player Layer Error

It show an error "A game object can only be in one layer. The layer needs to be in range[0 ... 31]". Pls help. the code is...

void AssignRemoteLayer()
{
gameObject.layer = LayerMask.NameToLayer (remoteLayerName);
}

Episode 13 27 minutes in: NullReferenceException

On the PlayerShoot Script on line 64 (at the time of this video in the series) I am receiving a NullReferenceException: Object reference not set to an instance of an object PlayerShoot.RpcDoShootEffects () (at Assets/Scripts/PlayerShoot.cs:64)

I followed the video as closely as I could, even rewatching this portion 4 times. I could not find this exact issue for anyone else. Is this because I am using Unity Version 2017.1.1f1 and the syntax has changed?

Some info which may help:
Clearing the Console errors and playing as stand alone in "Playe Mode" does not populate the error.
When I build the game and connect them (1 host 1 client) the error only populates when the client fires.
Additionally, not sure if this is the same issue or a separate one, but I am unable to see the muzzle flash of either player on the opposite screen. (As in my host cannot see client muzzle flash and vice versa)
[ClientRpc]
void RpcDoShootEffects()
{//Problem is below this line
weaponHolder.GetCurrentGraphics().muzzleFlash.Play();
}

I have been stuck on this for several hours so anyone who could explain my issue to me would be greatly appreciated.

Player setup script not working

There are no errors apart from more than one audio listener and when the host or client spawns in the scene camera doesn't turn off and controls change both characters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.