Need help to send a message from a gameobject to client

Hi I’m new to multiplayer in unity.I looked some code up but they didn’t work I have my network manager and it spawns different clients.I need to send a Message from one of my gameobjects to the clients.

       if (GetComponent<NetworkIdentity>().isLocalPlayer)
       {
            playerId = GetComponent<NetworkIdentity>().netId.ToString();
       }

By the above code I can distinguish each running instance of the game.So each games knows it’s player and saves it’s id in Player.cs.
from another gameObject I can use

 players = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject player in players)
            {
                if (player.GetComponent<Player>().playerId == "1")
                {...

so now first client can do things.Till it’s over then I want to send a message from the current gameobject to another client this time to another instance of the game so I need server and client code for that and receive it from the client to the current GameObject.

A TargetRpc is generally the way to go if I understand your question correctly.

https://docs.unity3d.com/ScriptReference/Networking.TargetRpcAttribute.html

Thanks for the reply.I just over explained it ,all i need to do is to send a string or float from a client to another one.I’m not really into server and clients so please check my reply and see if the link you referred is correct.Because if not and I go through it.I will give up on the whole thing.

The best way I came up with is using a network Animator and using empty animations with animation event on them that can cause some confusion because it produces the whole thing twice once on the server and once on the client but you can control it by the network id from networkIdentity.I’m not sure if it is efficient so please let me know if you people know.

Not sure what you mean by you’re “not really into server and clients”. Your game will have a computer acting as the server, even if it is a host also acting as a client. So you’re still doing server and client stuff. If you want to send data from 1 client to another [client you would do that through the server.

With Unet the usual way would be to send a Command to the server, and on the server send a ClientRpc or TargetRpc to the client(s). Alternatively you can use Unet Messages to replace either the Command or the Rpc. All of this is in the official documentation.

Don’t use a network animator as a way to just send basic types to clients. That’s just ridiculous.