为什么Photon中的代码速度慢?

时间:2016-06-30 22:49:29

标签: c# unity3d photon

当玩家吃掉当前的代码时,该代码应该通过网络在随机位置生成新食物。 代码在主客户端上运行顺畅,但对其他玩家来说有点慢。

知道我做错了什么?

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;
    }
}

0 个答案:

没有答案