【发布时间】:2020-07-05 14:30:21
【问题描述】:
我正在使用 PUN2,当玩家连接时,我希望他们的精灵渲染为随机颜色,并为所有其他玩家同步该颜色。
由于某种原因,以下代码阻止了其他玩家出现在屏幕上,但是我仍然可以在检查器中看到玩家对象。如果我删除 RPC 调用,我可以看到其他玩家正常,但他们的颜色不同步。
public class Player : MonoBehaviour
{
private PhotonView myPV;
public string nickname;
public Color color;
// Start is called before the first frame update
void Start()
{
myPV = GetComponent<PhotonView>();
if (myPV.IsMine)
{
gameObject.GetComponentInChildren<Camera>().enabled = true;
gameObject.GetComponentInChildren<TopDownCharacter>().enabled = true;
color = Random.ColorHSV();
myPV.RPC("RPC_SendColor", RpcTarget.AllBuffered);
}
}
[PunRPC]
void RPC_SendColor()
{
gameObject.GetComponentInChildren<SpriteRenderer>().color = color;
}
}
【问题讨论】:
标签: unity3d multiplayer photon