Why do I need [Command] for NetworkServer.Spawn() , but not for NetworkServer.Destroy()?
I have this script from a multiplayer shooter that I'm making , and I have a question about the use of the [Command] attribute
This is the code:
[Command]
public void CmdShoot()
{
//Creat the bullet
GameObject Bullet = (GameObject)Instantiate(bulletPrefab, Barrle.transform.position, Barrle.transform.rotation);
BulletController bc = Bullet.GetComponent<BulletController>();
bc.SetOrigin(this.transform.name);
NetworkServer.Spawn(Bullet);
//Shoot the bullet
Rigidbody rb = Bullet.GetComponent<Rigidbody>();
rb.AddForce(cam.transform.forward * BulletForce, ForceMode.VelocityChange);
}
//Called from the bullet when it hit something
[Command]
public void CmdHit(GameObject other,GameObject _bullet)
{
Debug.Log(other.transform.name);
GameObject bullet = _bullet;
if (other.GetComponent<NetworkIdentity>() != null)
{
//Destroy the coin if you hit it
if (other.transform.name.Equals("Coin"))
{
NetworkServer.Destroy(other.gameObject);
}
//Apply dmg to other player if hit it
else if (other.transform.tag.Equals("Player"))
{
Player playerHit = GameManager.GetPlayer(other.transform.name);
playerHit.TakeDamage(BulletForce);
}
}
//Destroy the bullet if you hit anything
NetworkServer.Destroy(bullet.gameObject);
}
Now if I remove the [Command] attribute from CmdShoot , the remote player isn't able to shoot , because he has no NetworkServer (as far as I understand)
I would assume it would be the same thing for CmdHit , and the remote player wont be able to destroy the bullet or the coin , because he does not have a NetworkServer.
But.. CmdHit works fine even without the [Command] attribute, and Im wondering why?
Your answer
Follow this Question
Related Questions
Unity Networking, where do I start? 0 Answers
Question to RPC and Command (Unet) 0 Answers
UNET - How to wait for NetworkConnection.Send(...) to finish? 0 Answers
syncvar not changing after command 0 Answers