- Home /
When a client click a Canvas button, does the server receive the info?
Hello.
I have some canvas that are spawned by the server with the player object. the problem I have is dont know why the server is not receiving the data i need.
The player clicks a button that executes a function in a script placed on it. This function is a [Command] funciton called Cmd.... this function only does one thing, increase a int variable like intVariable++;
The problem is that the script runing on the client is recieving that increase, but not the script runing on the server... what can be the problem? why the Cmd is not making the server to increase its variable?
Some sugestion? Thanks in advance!
Answer by tormentoarmagedoom · Mar 15, 2018 at 07:26 PM
Good day,
The solution is:
Button executes a method_A in the client who made the click.
This Method_A executes another Cmd_method_B in another script shared by clients and server that have Command Cmd property
Cmd_method_B do all you need server to do, for example, execute a Client_Rpc_Method_C that will make clients to do something.
This way, a client (player) can click a button, which server knows that can make players to do something.
If helped, please accept the answer :D
Hello,
I tried your solution, however, I received the following warning message: Trying to send command for object without authority., the Cmd_method_B was not called at all when I clicked the button.
This may be caused because you selected "client Authority" in the object containing the Cmd_method_B.
Or something like this. i mean, the "authority" options, are restrictive, so maybe you activated some authority in the wrong object
Hello,
Actually I tried both to select "client Authority" and deselect it, neither of them worked. I suspect the problem is because only the player can send Cmd_xx function to the server, and this is by design, whereas the button (the one which executes method_A) is not the player.
I checked the Unity doc, even though the commands can only be sent by the player, by assigning authority, non-player objects can also send commands. It means, the button must be assigned with client authority, it also means the button would become "networked". this is not what I want it to be, so I decide to redesign my program to bypass this problem.
Answer by watercat · Mar 15, 2018 at 05:48 PM
add pls the input butons which has standalone input module to yours input butons this is toutorial https://unity3d.com/learn/tutorials/topics/user-interface-ui/creating-main-menu
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
How can I call PhysX's simulate() and fetchResults() directly? 0 Answers
How to test Unity's new networking layer in separate game instances? 0 Answers
Why can't the client move a networked object ? 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers