Brackeys / MultiplayerFPS-Tutorial

A video series on making a multiplayer first-person shooter in Unity.
The Unlicense
654 stars 287 forks source link

Script is not working, help please #37

Closed NikunjGoyal119 closed 3 years ago

NikunjGoyal119 commented 3 years ago

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.

NikunjGoyal119 commented 3 years ago

issue is resolved