Multiplayer FPS in Unity (E06. Shooting)

Updated on July 3, 2017 in Discussions
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on July 3, 2017

when I shoot the opponent Nothing appears on my console. Need Help. Here is my code :-

 

PlayerShoot :-

 

using UnityEngine;

 

using UnityEngine.Networking;

 

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 referenced!”);
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.name == PLAYER_TAG)
{
CmdPlayerShot(_hit.collider.name);
}
}
}

 

[Command]
void CmdPlayerShot (string _ID)
{
Debug.Log( _ID + “has been shot”);
}

 

}

 

PlayerWeapon:-

 

using UnityEngine;

 

[System.Serializable]
public class PlayerWeapon {

 

public string name = “Glock”;

 

public float damage = 10f;
public float range = 100f;

 

}

  • Liked by
Reply