Hi,
I want to render a webcamtexture on a player in cube. So Every player in game have its own video on their cub.
Currently i am use RPC call but after few seconds my player disconnect and my game crashed
Any one have idea how to do it
I am using PUN 2
Script that i am using given blewo
void Update()
{
if (photonView.IsMine)
{
if (backCam == null)
{
backCam = new WebCamTexture(100, 100, 10);
}
if (!backCam.isPlaying)
{
backCam.Play();
}
Texture2D tex = new Texture2D(backCam.width, backCam.height, TextureFormat.RGB24, false);
tex.SetPixels(backCam.GetPixels());
tex.Apply();
byte[] bytes = tex.EncodeToJPG();
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("MyTextuerRPC", RpcTarget.All, bytes);
}
}
[PunRPC]
void MyTextuerRPC(byte bytes)
{
Texture2D tex = new Texture2D(2, 2);
// Load data into the texture.
tex.LoadImage(bytes);
// Assign texture to renderer's material.
GetComponent<Renderer>().material.mainTexture = tex;
}