My code works if I change the part to [Client], but I need it to be a [Command] so the server can damage and kill the player, but as command it doesn’t work and outputs no errors… Anyone know why this is happening?
using UnityEngine;
using UnityEngine.Networking;
public class PlayerShoot : NetworkBehaviour {
private const string PLAYER_TAG = "Player";
public PlayerWeapon weapon;
// 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 ("left click"))
{
Debug.Log ("clicking to shoot");
Shoot ();
}
}
[Client]
void Shoot()
{
Debug.Log ("Calling shots");
RaycastHit _hit;
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, weapon.damage, mask))
{
if (_hit.collider.tag == PLAYER_TAG)
{
CmdPlayerShot (_hit.collider.name, weapon.damage);
}
}
}
[Command] // This is the part I am talking about, everything up until this point works
void CmdPlayerShot (string _playerID, int _damage)
{
Debug.Log (_playerID + " has been shot.");
Player _player = GameManager.GetPlayer (_playerID);
_player.RpcTakeDamage(_damage);
}
}
P.S. I got this code from the Brackeyes FPS Tutorial
I tried it out, and the code fired, but because it isn’t a command the server didn’t kill the other player, and nothing he just snapped right back to his position
But I dont see the kill method, only like Damage, and, also, u dont change HP of player on Server, you only do it for client _player.RpcTakeDamage(_damage); use SyncVars.