Calling Bool in Network Command Not Working
Hello, So I'm currently working on an online FPS and trying to make it to where players can pick up loot or items. The problem is I need to have the item get destroyed on all clients and no matter what I try, either it only disables for one client or for neither.
This is where I'm at in trying to debug this (I'm still pretty new to programming so it could very well be I'm just still too stupid lol) so it's pretty messy at the moment with disabled lines and such. I really want to know why once CmdCollected is called I get my Debug Log but the boolean is not changed. What makes that fact even more confusing is earlier in my debugging I had the CmdCollected calling on "_hit.collider.GetComponent().value" and it worked perfectly fine when applying the value to the client player's current loot (on both clients as well).
So to put it short I need the bool "collected" (Which has [SyncVar] btw) for the Loot class to be turned true for all clients so that the object will call on it's destroy operation for all players.
Been smacking my head against this for the past 3 hours and really need some saving haha.
void Update () {
if(Input.GetButtonDown("Interact")){
CmdInteract ();
}
}
// [Client]
void CmdInteract(){
RaycastHit _hit;
if (Physics.Raycast (cam.transform.position, cam.transform.forward, out _hit, 15, mask)) {
if (_hit.collider.tag == LOOT_TAG) {
GetComponent<Player> ().loot = GetComponent<Player> ().loot + _hit.collider.GetComponent<Loot>().value;
// _hit.collider.GetComponent<Loot>().collected = true;
CmdCollected (_hit.collider.GetComponent<Loot>().collected);
}
}
}
[Command]
void CmdCollected(bool _isCollected){
Debug.Log ("Accessed Command");
_isCollected = true;
}
Your answer
Follow this Question
Related Questions
Server Command Call not working when inside an if which checks for hasAuthority and a bool 0 Answers
Spawning Network Objects from the client | Unity Netcode For Gameobjects 0 Answers
Unet: [Command] not running 1 Answer
syncvar not changing after command 0 Answers
How to get player game objects of network on server? 1 Answer