C# 为什么这段代码的光子传输速度慢?

C# 为什么这段代码的光子传输速度慢?,c#,unity3d,photon,C#,Unity3d,Photon,当玩家吃下当前的食物时,这个代码应该在网络上的任意位置生成新的食物。 代码在主客户端上运行平稳,但在其他玩家上运行有点慢 知道我做错了什么吗 using UnityEngine; using System.Collections; public class FoodCollision : Photon.MonoBehaviour { public static float amtOfIncreaseSpeed = 1f; public static float amtOfInc

当玩家吃下当前的食物时,这个代码应该在网络上的任意位置生成新的食物。 代码在主客户端上运行平稳,但在其他玩家上运行有点慢

知道我做错了什么吗

using UnityEngine;
using System.Collections;

public class FoodCollision : Photon.MonoBehaviour
{
    public static float amtOfIncreaseSpeed = 1f;
    public static float amtOfIncreaseHealth = 1f;
    public static float ratioOfSpeed = 150.0f;
    public static float increaseSize = 0.001f;

    PhotonView photonView;
    BoxCollider2D boxCollider;
    SpriteRenderer sp;
    float widthOfBoard, heightOfBoard;
    void Awake()
    {
        photonView = PhotonView.Get(this);
        boxCollider = GetComponent<BoxCollider2D>();
        sp = GetComponent<SpriteRenderer>();
        widthOfBoard = FoodManager.instance.widthOfBoard;
        heightOfBoard = FoodManager.instance.heightOfBoard;
    }

    public void ResetGO()
    {
        sp.enabled = false;
        photonView.RPC("ResetGORPC", PhotonTargets.AllBuffered); 
    }

    [PunRPC]
    void ResetGORPC()
    {
        Vector3 position = new Vector3(Random.Range(-widthOfBoard / 2, widthOfBoard / 2), Random.Range(-heightOfBoard / 2, heightOfBoard / 2), 0);
        transform.position = position;
        transform.localScale = Vector3.one;
        sp.enabled = true;
    }
}
使用UnityEngine;
使用系统集合;
公共类FoodCollision:Photon.monobhavior
{
公共静态浮点AMTOF递增速度=1f;
公共静态浮动amtofEncreaseHealth=1f;
公共静态浮动率速度=150.0f;
公共静态浮动增量大小=0.001f;
PhotonView PhotonView;
BoxCollider2D boxCollider;
喷雾器;
浮板宽度、浮板高度;
无效唤醒()
{
photonView=photonView.Get(这个);
boxCollider=GetComponent();
sp=GetComponent();
widthOfBoard=FoodManager.instance.widthOfBoard;
heightOfBoard=FoodManager.instance.heightOfBoard;
}
公共无效重置GO()
{
sp.enabled=false;
RPC(“ResetGORPC”,PhotonTargets.AllBuffered);
}
[扑克牌]
void ResetGORPC()
{
Vector3位置=新的Vector3(随机范围(-Board宽度/2,Board宽度/2),随机范围(-Board高度/2,Board高度/2),0);
变换位置=位置;
transform.localScale=Vector3.1;
sp.enabled=true;
}
}

探查器是否显示了有趣的内容?什么是“慢”的意思?PhotonTargets.AllBuffered会影响性能,因为它会累积从游戏开始触发的所有RPC,并将所有RPC发送到新加入的客户端。当使用大量RPC时,不建议使用此选项。当新客户加入时,请尝试使用房间属性来获取食物位置,或者使用主客户的这些位置更新新客户。