[Unity Network] Spawn prefab and change color
Hello. (Sorry for my bad english, it's not my first language).
For a project, i need to create an hexagonal map (randomly). And actually i've some strong problem with the Unity Network.
So, now i just want something more "simple" to test : - The hoster and player(s) join the game. (it's ok). - I use a lobby, so when all player are ready, change scene (it's ok). - Load all scripts and one in particulary called "Generate".
There is the script at the end. On my hoster, it's ok, one of my spawned cube is blue. But on the client, nothing, they are all black.
I've tried some other possibilities, but actually i just don't understand why i can't change the color while the transform perfectly work.
So, if you can help me a bit, it would be nice because i'm lost :(. Thanks !
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Generate : NetworkBehaviour {
public GameObject Acube;
// Use this for initialization
void Start () {
if(isServer)
{
CreateObjet(0,0,0);
CreateObjet(10,0,0);
CreateObjet(0,0,10);
GameObject myItem = GameObject.Find("Cube(Clone)");
RpcChangeColor(myItem);
} else
{
print("i'm not the server");
}
}
public void CreateObjet (int a, int b, int c)
{
GameObject myCube = Instantiate(Acube);
myCube.transform.position = new Vector3(a, b, c);
NetworkServer.Spawn(myCube);
}
[ClientRpc]
public void RpcChangeColor (GameObject obj)
{
NetworkIdentity objID = obj.GetComponent<NetworkIdentity>();
objID.AssignClientAuthority(connectionToClient);
objID.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.blue);
}
// Update is called once per frame
void Update () {
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612162214im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Realtime noises in unlit shader graph 0 Answers
Scaling a plane in ExecuteAlways mode removes color 0 Answers
FPS Microgame and weapon display 0 Answers
How to load material onto sphere? 1 Answer