Buttons with Networking

Hello,

I’ve been struggling with this issue ever since I started learning networking with Unity. I am making a game where players press buttons on in-game control panel to operate a ship.

It seems that all [commands] must be called by a script that is attached to the player object, is this true?

So if I have a button in game that says “turn ship right”, the player script would have to know where the ship controller is and tell it directly to turn right, which will be difficult if we have many buttons that do very different things, they would all need to be attached to the player.

SendMessage does not seem to work. I tried to generalize by trying issue [Command] on the player object that was just wrapper for SendMessage so I can interact with the buttons without having to know exactly which function each maps on the player object.

Also Canvas → GUI onClick do not work. If a client clicks a button that has an onClick that maps to the ship.turnright, the server will not hear it, and cmdturnright will not work because its not coming from the player.

What is the best way to approach this without packing every single possible button script onto the player object?

Hey kibbles,

I’m a fellow networking beginner and this was the sort of thing that stumped me for hours… And I couldn’t find anything on it…

But I’ll try to help, nonetheless.

  1. could you have an enumeration with the different actions ? For example the function could be SomeFunction(ActionEnum.SomeAction, intActionValue); . Then it’s just one function followed by switch statements… Right?

  2. instead of a player being ng the networked point, what about adding a networkid to a ship class? Would that work (server.spawnobjects might be needed…)

Sorry if this is no help… Still learning (and getting stuck) myself, lol