- Home /
Send Texture Over Network
I want send my texture to other Client. I use a code for RenderTexture and Works Nice! and change that to use for Texture2D But Client see a textrue from one side of my camera or nothing!
public Texture2D MyTexture;
public byte[] receivedBytes;
public byte[] N;
public Texture2D texi;
void Start () {
texi = new Texture2D(MyTexture.width,MyTexture.height);
}
void Update () {
if(Network.isServer){
if(Input.GetKeyDown(KeyCode.X)){
StartCoroutine(GetRenderTexturePixel(MyTexture));
networkView.RPC("Send", RPCMode.All,N);
}
}
if(Network.isClient){
if(Input.GetKeyDown(KeyCode.X)){
texi.LoadImage(N);
renderer.material.mainTexture = texi;
}
}
}
IEnumerator GetRenderTexturePixel(Texture2D tex)
{
Texture2D tempTex = new Texture2D(tex.width, tex.height);
yield return new WaitForEndOfFrame();
tempTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
tempTex.Apply();
N= tempTex.EncodeToPNG();
}
[RPC]
public void Send(byte[] receivedByte){
receivedBytes=receivedByte;
}
Comment
Answer by Omidja · Nov 29, 2014 at 09:14 AM
hi. i solved it in past! send texture.EncodeToPNG () in a rpc and in void:
[RPC]
void SendTextures(byte[] receivedByte){
receivedTexture = null;
receivedTexture = new Texture2D(1, 1);
receivedTexture.LoadImage(receivedByte);
GetComponent<Renderer>().material.mainTexture = receivedTexture;
}
Your answer
Follow this Question
Related Questions
Sending bulk data via rpc 1 Answer
[Solved]Tell everyone what my texture is 0 Answers
Share Texture 0 Answers
Really quick/easy question about RPCs 1 Answer
Check bool on another player 1 Answer