I’ve a script on my participant gameobjects, once I shoot, it executes the command, Humanoid.take_damage().
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;
utilizing Mirror;
class GunScript : NetworkBehaviour {
void Replace() {
if (isLocalPlayer) {
if (Physics.Raycast(digital camera.remodel.place, digital camera.remodel.ahead, out hit, Mathf.Infinity)) {
if (hit.remodel.tag == "Participant") {
Debug.Log(hasAuthority);
if (hasAuthority) {
hit.remodel.father or mother.GetComponent<Humanoid>().take_damage(humanoid.injury);
}
}
}
}
}
}
After I shoot, the output is “True”, which implies that the native participant has authority.
That is my code for Humanoid.take_damage()
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;
utilizing Mirror;
class Humanoid : NetworkBehaviour {
float _health;
public float well being {
get {
return _health;
}
}
bool useless = false;
[Command]
public void take_damage(float injury) {
if (!useless) {
if (injury >= _health) {
_health = 0;
} else {
_health -= injury;
}
if (_health == 0) {
die();
}
print(tag + " is now at: " + _health + " well being.");
} else {
Debug.Log("No injury was dealt to " + identify + "; He is useless.");
}
}
}
This command is rarely executed although for some cause. I’m calling it, however neither "No injury was dealt to " + identify + "; He is useless." or tag + " is now at: " + _health + " well being." is printed.
Additionally, once I exchange [Command] with [Command(requiresAuthority = false)], it really works. It is as if once I name Humanoid.take_damage() in my GunScript, it does not have authority!
Thanks.

