Send Random Color's Through the Network

Options
how i can send a random-generated color in network? this is my current script, my script don't sync the colors(sorry for my english, i'm brazilyan :p)

Script: (C#)
using UnityEngine;
using System.Collections;

public class RandomColor : MonoBehaviour {

public Renderer renderer;
// Use this for initialization
void Start ()
{
ChangeColor(new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)));
}

// Update is called once per frame
void Update ()
{

}

[RPC]
void ChangeColor(Vector3 color)
{
renderer = GetComponent<MeshRenderer>();
renderer.material.color = new Color( Random.Range(0f,1f),Random.Range(0f,1f),Random.Range(0f,1f) );

if(GetComponent<PhotonView>().isMine)
{
GetComponent<PhotonView>().RPC ("ChangeColor", PhotonTargets.AllBuffered, color);
}
}

void OnPhotonSerializeView()
{
ChangeColor(new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)));
}
}


And this other script pick a random texture, how i apply the texture for network?
Script (C#)

using UnityEngine;
using System.Collections;

public class SetRandomTexture : MonoBehaviour {

public Texture2D[] textures;

// Use this for initialization
void Start ()
{
transform.GetComponent<Renderer>().material.SetTexture ("_MainTex", textures[Random.Range(0, textures.Length)]);
}

// Update is called once per frame
void Update ()
{

}

[RPC]
void SetTexture()
{

}
}


(the first script is attached to a Capsule, and the second to a Cylinder)

Comments

  • vadim
    Options
    You can do it in many ways depending on how you use this color. Probably the simplest way would be setting room properties:
    1st client: PhotonNetwork.room.SetCustomProperties(new Hashtable(){{"color",color}});
    other clients: PhotonNetwork.room.customProperties["color"];
  • I Want to make this: When i join, I make a random color and apply to the player, for only this player, and the others can see the random color, each player have his color, and his color is through the network, if you can post a script =p
  • vadim
    Options
    Then you need player custom properties.
    Assets\Photon Unity Networking\UtilityScripts\PunPlayerScores.cs script is example of player properties usage.
  • I'm Newbie on C# and Very Very Newbie on PhotonNetwork '-' plz help-me, and I don't understand english good '-' I need an script with the hashtable's of the color? I don't understand nothing of Photon plz help =p

    if you can make an script working for me :) bye bye
  • I'll give it up, and make some other characters ...
  • vadim
    Options
    Sorry, we can't code for you.
    Invest some time in C# and Photon learning.
    You need basic knowledge level to understand how PunPlayerScores.cs works.