Iβm studying some of the basics of Unity 5, UNET, and networking. I made a simple 3D game in which you go and change the colors of objects. But now I want to make it multi-user, and I have a lot of problems figuring out how to send changes over the network so that all players can see the color change of one player.
Part of the problem is that it was difficult to find the answer using the new UNET networking engine. And sometimes I come across answers that are for an older way.
So, the main question is how to change the properties of a GameIbject property other than a player? Color, shape, size, etc.
Here is some code that I have now - and I had many different versions, so Iβll just post the current version:
using UnityEngine; using System.Collections; using UnityEngine.Networking; public class Player_Paint : NetworkBehaviour { private int range = 200; [SerializeField] private Transform camTransform; private RaycastHit hit; [SyncVar] private Color objectColor; [SyncVar] private GameObject objIdentity; void Update () { CheckIfPainting(); } void CheckIfPainting(){ if(Input.GetMouseButtonDown(0)) { if (Physics.Raycast (camTransform.TransformPoint (0, 0, 0.5f), camTransform.forward, out hit, range)) { string objName = hit.transform.name; CmdPaint(objName); } } } [ClientRpc] void RpcPaint(){ objIdentity.GetComponent<Renderer>().material.color = objectColor; } [Command] void CmdPaint(string name) { objIdentity = GameObject.Find (name);
I tried many solutions, including writing a separate script object whose color I want to change, including the [SyncVar] and hook functions. I also tried Debug.Log for each of the functions that I expect to update on the objects, and they execute with the expected data.
I really don't know what else to do. I feel that this is a VERY simple thing that I want to do, but I have not come across non-player GameObject synchronization in any questions, tutorials or other resources. Any ideas at all would be helpful, thanks.