- Home /
How to distinguish each characters in networkplay?
I'm using one prefab as a user character in multiplay game.
If 5 users connected, each character's names are as below.
Prefabname(Clone) Prefabname(Clone)Remote Prefabname(Clone)Remote Prefabname(Clone)Remote Prefabname(Clone)Remote
I want to give different name to each character.
Anyone has idea?
Answer by Atnas1010 · Nov 02, 2010 at 01:28 PM
You could do you own instantiating(see here http://unity3d.com/support/documentation/ScriptReference/Network.AllocateViewID.html), and send the name of the player as a parameter in the RPC call. And then set the name of the gameobject when you add it.
Does that solve your problem?
Slightly modified sample code from scripting reference:
var cubePrefab : Transform;
function OnGUI () { if (GUILayout.Button("SpawnBox")) { var name = "John"; var viewID = Network.AllocateViewID(); networkView.RPC("SpawnBox", RPCMode.AllBuffered,viewID, transform.position, name); } }
@RPC function SpawnBox (viewID : NetworkViewID, location : Vector3, name : String) { // Instantate the prefab locally var clone : Transform; clone = Instantiate(cubePrefab, location, Quaternion.identity) as Transform; clone.name = name; var nView : NetworkView; nView = clone.GetComponent(NetworkView); nView.viewID = viewID; }
Thank you very much for info. But unfortunately I'm quite new in Unity so not easy to catch up. If there is example code it will be a great help. Could you show me some example code ?
Example code for doing your own instantiating is in the link in my post. But I'll just edit my post to have a copy of that code, with the name thing you were looking for.
Thanks for your post. This answer saved me from headache. I tried to find this info nearly two weeks.
Your answer
Follow this Question
Related Questions
Networking Player Nametag 1 Answer
A name For the Character Please Help 3 Answers
Network object references to each other 1 Answer
Displaying players name above in multiplayer 1 Answer
Multiplayer names problem 2 Answers